| 1 | package gocachescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/ |
| 2 | |
| 3 | import ( |
| 4 | "bytesscip-go gomod github.com/golang/go/src go1.24.4 bytes/" |
| 5 | "fmtscip-go gomod github.com/golang/go/src go1.24.4 fmt/" |
| 6 | "math/randscip-go gomod github.com/golang/go/src go1.24.4 `math/rand`/" |
| 7 | "strconvscip-go gomod github.com/golang/go/src go1.24.4 strconv/" |
| 8 | "stringsscip-go gomod github.com/golang/go/src go1.24.4 strings/" |
| 9 | "testingscip-go gomod github.com/golang/go/src go1.24.4 testing/" |
| 10 | "timescip-go gomod github.com/golang/go/src go1.24.4 time/" |
| 11 | ) |
| 12 | |
| 13 | func TestNewCachescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/TestNewCache().(t *testingscip-go gomod github.com/golang/go/src go1.24.4 testing/.Tscip-go gomod github.com/golang/go/src go1.24.4 testing/T#) { |
| 14 | cache := NewCachescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/NewCache().().WithMaxSizescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#WithMaxSize().(1234).WithEvictionPolicyscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#WithEvictionPolicy().(LeastRecentlyUsedscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/LeastRecentlyUsed.) |
| 15 | if cache.MaxMemoryUsagescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#MaxMemoryUsage().() != NoMaxMemoryUsagescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/NoMaxMemoryUsage. { |
| 16 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("shouldn't have a max memory usage configured") |
| 17 | } |
| 18 | if cache.EvictionPolicyscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#EvictionPolicy().() != LeastRecentlyUsedscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/LeastRecentlyUsed. { |
| 19 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("should've had a LeastRecentlyUsed eviction policy") |
| 20 | } |
| 21 | if cache.defaultTTLscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#defaultTTL. != NoExpirationscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/NoExpiration. { |
| 22 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("should've had a default TTL of NoExpiration") |
| 23 | } |
| 24 | if cache.MaxSizescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#MaxSize().() != 1234 { |
| 25 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("should've had a max cache size of 1234") |
| 26 | } |
| 27 | if cache.MemoryUsagescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#MemoryUsage().() != 0 { |
| 28 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("should've had a memory usage of 0") |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | func TestCache_Statsscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/TestCache_Stats().(t *testingscip-go gomod github.com/golang/go/src go1.24.4 testing/.Tscip-go gomod github.com/golang/go/src go1.24.4 testing/T#) { |
| 33 | cache := NewCachescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/NewCache().().WithMaxSizescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#WithMaxSize().(1234).WithEvictionPolicyscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#WithEvictionPolicy().(LeastRecentlyUsedscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/LeastRecentlyUsed.) |
| 34 | cache.Setscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Set().("key", "value") |
| 35 | if cache.Statsscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Stats().().Hitsscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Statistics#Hits. != 0 { |
| 36 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("should have 0 hits") |
| 37 | } |
| 38 | if cache.Statsscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Stats().().Missesscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Statistics#Misses. != 0 { |
| 39 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("should have 0 misses") |
| 40 | } |
| 41 | cache.Getscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Get().("key") |
| 42 | if cache.Statsscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Stats().().Hitsscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Statistics#Hits. != 1 { |
| 43 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("should have 1 hit") |
| 44 | } |
| 45 | if cache.Statsscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Stats().().Missesscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Statistics#Misses. != 0 { |
| 46 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("should have 0 misses") |
| 47 | } |
| 48 | cache.Getscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Get().("key-that-does-not-exist") |
| 49 | if cache.Statsscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Stats().().Hitsscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Statistics#Hits. != 1 { |
| 50 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("should have 1 hit") |
| 51 | } |
| 52 | if cache.Statsscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Stats().().Missesscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Statistics#Misses. != 1 { |
| 53 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("should have 1 miss") |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | func TestCache_Getscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/TestCache_Get().(t *testingscip-go gomod github.com/golang/go/src go1.24.4 testing/.Tscip-go gomod github.com/golang/go/src go1.24.4 testing/T#) { |
| 58 | cache := NewCachescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/NewCache().().WithMaxSizescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#WithMaxSize().(10) |
| 59 | cache.Setscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Set().("key", "value") |
| 60 | value, ok := cache.Getscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Get().("key") |
| 61 | if !ok { |
| 62 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("expected key to exist") |
| 63 | } |
| 64 | if value != "value" { |
| 65 | t.Errorfscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Errorf().("expected: %s, but got: %s", "value", value) |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | func TestCache_GetExpiredscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/TestCache_GetExpired().(t *testingscip-go gomod github.com/golang/go/src go1.24.4 testing/.Tscip-go gomod github.com/golang/go/src go1.24.4 testing/T#) { |
| 70 | cache := NewCachescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/NewCache().() |
| 71 | cache.SetWithTTLscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#SetWithTTL().("key", "value", timescip-go gomod github.com/golang/go/src go1.24.4 time/.Millisecondscip-go gomod github.com/golang/go/src go1.24.4 time/Millisecond.) |
| 72 | timescip-go gomod github.com/golang/go/src go1.24.4 time/.Sleepscip-go gomod github.com/golang/go/src go1.24.4 time/Sleep().(2 * timescip-go gomod github.com/golang/go/src go1.24.4 time/.Millisecondscip-go gomod github.com/golang/go/src go1.24.4 time/Millisecond.) |
| 73 | _, ok := cache.Getscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Get().("key") |
| 74 | if ok { |
| 75 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("expected key to be expired") |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | func TestCache_GetEntryThatHasNotExpiredYetscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/TestCache_GetEntryThatHasNotExpiredYet().(t *testingscip-go gomod github.com/golang/go/src go1.24.4 testing/.Tscip-go gomod github.com/golang/go/src go1.24.4 testing/T#) { |
| 80 | cache := NewCachescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/NewCache().() |
| 81 | cache.SetWithTTLscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#SetWithTTL().("key", "value", timescip-go gomod github.com/golang/go/src go1.24.4 time/.Hourscip-go gomod github.com/golang/go/src go1.24.4 time/Hour.) |
| 82 | _, ok := cache.Getscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Get().("key") |
| 83 | if !ok { |
| 84 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("expected key to not have expired") |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | func TestCache_GetValuescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/TestCache_GetValue().(t *testingscip-go gomod github.com/golang/go/src go1.24.4 testing/.Tscip-go gomod github.com/golang/go/src go1.24.4 testing/T#) { |
| 89 | cache := NewCachescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/NewCache().().WithMaxSizescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#WithMaxSize().(10) |
| 90 | cache.Setscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Set().("key", "value") |
| 91 | value := cache.GetValuescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#GetValue().("key") |
| 92 | if value != "value" { |
| 93 | t.Errorfscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Errorf().("expected: %s, but got: %s", "value", value) |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | func TestCache_GetByKeysscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/TestCache_GetByKeys().(t *testingscip-go gomod github.com/golang/go/src go1.24.4 testing/.Tscip-go gomod github.com/golang/go/src go1.24.4 testing/T#) { |
| 98 | cache := NewCachescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/NewCache().().WithMaxSizescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#WithMaxSize().(10) |
| 99 | cache.Setscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Set().("key1", "value1") |
| 100 | cache.Setscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Set().("key2", "value2") |
| 101 | keyValues := cache.GetByKeysscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#GetByKeys().([]string{"key1", "key2", "key3"}) |
| 102 | if len(keyValues) != 3 { |
| 103 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("expected length of map to be 3") |
| 104 | } |
| 105 | if keyValues["key1"] != "value1" { |
| 106 | t.Errorfscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Errorf().("expected: %s, but got: %s", "value1", keyValues["key1"]) |
| 107 | } |
| 108 | if keyValues["key2"] != "value2" { |
| 109 | t.Errorfscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Errorf().("expected: %s, but got: %s", "value2", keyValues["key2"]) |
| 110 | } |
| 111 | if value, ok := keyValues["key3"]; !ok || value != nil { |
| 112 | t.Errorfscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Errorf().("expected key3 to exist and be nil, but got: %s", value) |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | func TestCache_GetAllscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/TestCache_GetAll().(t *testingscip-go gomod github.com/golang/go/src go1.24.4 testing/.Tscip-go gomod github.com/golang/go/src go1.24.4 testing/T#) { |
| 117 | cache := NewCachescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/NewCache().().WithMaxSizescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#WithMaxSize().(10) |
| 118 | cache.Setscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Set().("key1", "value1") |
| 119 | cache.Setscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Set().("key2", "value2") |
| 120 | keyValues := cache.GetAllscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#GetAll().() |
| 121 | if len(keyValues) != 2 { |
| 122 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("expected length of map to be 2") |
| 123 | } |
| 124 | if keyValues["key1"] != "value1" { |
| 125 | t.Errorfscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Errorf().("expected: %s, but got: %s", "value1", keyValues["key1"]) |
| 126 | } |
| 127 | if keyValues["key2"] != "value2" { |
| 128 | t.Errorfscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Errorf().("expected: %s, but got: %s", "value2", keyValues["key2"]) |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | func TestCache_GetAllWhenOneKeyIsExpiredscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/TestCache_GetAllWhenOneKeyIsExpired().(t *testingscip-go gomod github.com/golang/go/src go1.24.4 testing/.Tscip-go gomod github.com/golang/go/src go1.24.4 testing/T#) { |
| 133 | cache := NewCachescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/NewCache().().WithMaxSizescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#WithMaxSize().(10) |
| 134 | cache.Setscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Set().("key1", "value1") |
| 135 | cache.Setscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Set().("key2", "value2") |
| 136 | cache.SetWithTTLscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#SetWithTTL().("key3", "value3", timescip-go gomod github.com/golang/go/src go1.24.4 time/.Nanosecondscip-go gomod github.com/golang/go/src go1.24.4 time/Nanosecond.) |
| 137 | timescip-go gomod github.com/golang/go/src go1.24.4 time/.Sleepscip-go gomod github.com/golang/go/src go1.24.4 time/Sleep().(timescip-go gomod github.com/golang/go/src go1.24.4 time/.Millisecondscip-go gomod github.com/golang/go/src go1.24.4 time/Millisecond.) |
| 138 | keyValues := cache.GetAllscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#GetAll().() |
| 139 | if len(keyValues) != 2 { |
| 140 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("expected length of map to be 2") |
| 141 | } |
| 142 | if keyValues["key1"] != "value1" { |
| 143 | t.Errorfscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Errorf().("expected: %s, but got: %s", "value1", keyValues["key1"]) |
| 144 | } |
| 145 | if keyValues["key2"] != "value2" { |
| 146 | t.Errorfscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Errorf().("expected: %s, but got: %s", "value2", keyValues["key2"]) |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | func TestCache_GetKeysByPatternscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/TestCache_GetKeysByPattern().(t *testingscip-go gomod github.com/golang/go/src go1.24.4 testing/.Tscip-go gomod github.com/golang/go/src go1.24.4 testing/T#) { |
| 151 | // All keys match |
| 152 | testGetKeysByPatternscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/testGetKeysByPattern().(t, []string{"key1", "key2", "key3", "key4"}, "key*", 0, 4) |
| 153 | testGetKeysByPatternscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/testGetKeysByPattern().(t, []string{"key1", "key2", "key3", "key4"}, "*y*", 0, 4) |
| 154 | testGetKeysByPatternscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/testGetKeysByPattern().(t, []string{"key1", "key2", "key3", "key4"}, "*key*", 0, 4) |
| 155 | testGetKeysByPatternscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/testGetKeysByPattern().(t, []string{"key1", "key2", "key3", "key4"}, "*", 0, 4) |
| 156 | // All keys match but limit is reached |
| 157 | testGetKeysByPatternscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/testGetKeysByPattern().(t, []string{"key1", "key2", "key3", "key4"}, "*", 2, 2) |
| 158 | // Some keys match |
| 159 | testGetKeysByPatternscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/testGetKeysByPattern().(t, []string{"key1", "key2", "key3", "key4", "key11"}, "key1*", 0, 2) |
| 160 | testGetKeysByPatternscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/testGetKeysByPattern().(t, []string{"key1", "key2", "key3", "key4", "key11"}, "*key1*", 0, 2) |
| 161 | testGetKeysByPatternscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/testGetKeysByPattern().(t, []string{"key1", "key2", "key3", "key4", "key11", "key111"}, "key1*", 0, 3) |
| 162 | testGetKeysByPatternscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/testGetKeysByPattern().(t, []string{"key1", "key2", "key3", "key4", "key11", "key111"}, "key11*", 0, 2) |
| 163 | testGetKeysByPatternscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/testGetKeysByPattern().(t, []string{"key1", "key2", "key3", "key4", "key11", "key111"}, "*11*", 0, 2) |
| 164 | testGetKeysByPatternscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/testGetKeysByPattern().(t, []string{"key1", "key2", "key3", "key4", "key11", "key111"}, "k*1*", 0, 3) |
| 165 | testGetKeysByPatternscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/testGetKeysByPattern().(t, []string{"key1", "key2", "key3", "key4", "key11", "key111"}, "*k*1", 0, 3) |
| 166 | // No keys match |
| 167 | testGetKeysByPatternscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/testGetKeysByPattern().(t, []string{"key1", "key2", "key3", "key4"}, "image*", 0, 0) |
| 168 | testGetKeysByPatternscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/testGetKeysByPattern().(t, []string{"key1", "key2", "key3", "key4"}, "?", 0, 0) |
| 169 | } |
| 170 | |
| 171 | func testGetKeysByPatternscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/testGetKeysByPattern().(t *testingscip-go gomod github.com/golang/go/src go1.24.4 testing/.Tscip-go gomod github.com/golang/go/src go1.24.4 testing/T#, keys []string, pattern string, limit, expectedMatchingKeys int) { |
| 172 | cache := NewCachescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/NewCache().().WithMaxSizescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#WithMaxSize().(len(keys)) |
| 173 | for _, key := range keys { |
| 174 | cache.Setscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Set().(key, key) |
| 175 | } |
| 176 | matchingKeys := cache.GetKeysByPatternscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#GetKeysByPattern().(pattern, limit) |
| 177 | if len(matchingKeys) != expectedMatchingKeys { |
| 178 | t.Errorfscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Errorf().("expected to have %d keys to match pattern '%s', got %d", expectedMatchingKeys, pattern, len(matchingKeys)) |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | func TestCache_GetKeysByPatternWithExpiredKeyscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/TestCache_GetKeysByPatternWithExpiredKey().(t *testingscip-go gomod github.com/golang/go/src go1.24.4 testing/.Tscip-go gomod github.com/golang/go/src go1.24.4 testing/T#) { |
| 183 | cache := NewCachescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/NewCache().().WithMaxSizescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#WithMaxSize().(10) |
| 184 | cache.SetWithTTLscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#SetWithTTL().("key", "value", 10*timescip-go gomod github.com/golang/go/src go1.24.4 time/.Millisecondscip-go gomod github.com/golang/go/src go1.24.4 time/Millisecond.) |
| 185 | // The cache entry shouldn't have expired yet, so GetKeysByPattern should return 1 key |
| 186 | if matchingKeys := cache.GetKeysByPatternscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#GetKeysByPattern().("*", 0); len(matchingKeys) != 1 { |
| 187 | t.Errorfscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Errorf().("expected to have %d keys to match pattern '%s', got %d", 1, "*", len(matchingKeys)) |
| 188 | } |
| 189 | timescip-go gomod github.com/golang/go/src go1.24.4 time/.Sleepscip-go gomod github.com/golang/go/src go1.24.4 time/Sleep().(30 * timescip-go gomod github.com/golang/go/src go1.24.4 time/.Millisecondscip-go gomod github.com/golang/go/src go1.24.4 time/Millisecond.) |
| 190 | // Since the key expired, the same call should return 0 keys instead of 1 |
| 191 | if matchingKeys := cache.GetKeysByPatternscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#GetKeysByPattern().("*", 0); len(matchingKeys) != 0 { |
| 192 | t.Errorfscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Errorf().("expected to have %d keys to match pattern '%s', got %d", 0, "*", len(matchingKeys)) |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | func TestCache_Setscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/TestCache_Set().(t *testingscip-go gomod github.com/golang/go/src go1.24.4 testing/.Tscip-go gomod github.com/golang/go/src go1.24.4 testing/T#) { |
| 197 | cache := NewCachescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/NewCache().().WithMaxSizescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#WithMaxSize().(NoMaxSizescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/NoMaxSize.) |
| 198 | cache.Setscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Set().("key", "value") |
| 199 | value, ok := cache.Getscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Get().("key") |
| 200 | if !ok { |
| 201 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("expected key to exist") |
| 202 | } |
| 203 | if value != "value" { |
| 204 | t.Errorfscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Errorf().("expected: %s, but got: %s", "value", value) |
| 205 | } |
| 206 | cache.Setscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Set().("key", "newvalue") |
| 207 | value, ok = cache.Getscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Get().("key") |
| 208 | if !ok { |
| 209 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("expected key to exist") |
| 210 | } |
| 211 | if value != "newvalue" { |
| 212 | t.Errorfscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Errorf().("expected: %s, but got: %s", "newvalue", value) |
| 213 | } |
| 214 | } |
| 215 | |
| 216 | func TestCache_SetDifferentTypesOfDatascip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/TestCache_SetDifferentTypesOfData().(t *testingscip-go gomod github.com/golang/go/src go1.24.4 testing/.Tscip-go gomod github.com/golang/go/src go1.24.4 testing/T#) { |
| 217 | cache := NewCachescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/NewCache().().WithMaxSizescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#WithMaxSize().(NoMaxSizescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/NoMaxSize.) |
| 218 | cache.Setscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Set().("key", 1) |
| 219 | value, ok := cache.Getscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Get().("key") |
| 220 | if !ok { |
| 221 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("expected key to exist") |
| 222 | } |
| 223 | if value != 1 { |
| 224 | t.Errorfscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Errorf().("expected: %v, but got: %v", 1, value) |
| 225 | } |
| 226 | cache.Setscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Set().("key", struct{ Test string }{Test: "test"}) |
| 227 | value, ok = cache.Getscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Get().("key") |
| 228 | if !ok { |
| 229 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("expected key to exist") |
| 230 | } |
| 231 | if value.(struct{ Test string }) != struct{ Test string }{Test: "test"} { |
| 232 | t.Errorfscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Errorf().("expected: %s, but got: %s", "newvalue", value) |
| 233 | } |
| 234 | } |
| 235 | |
| 236 | func TestCache_SetGetIntscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/TestCache_SetGetInt().(t *testingscip-go gomod github.com/golang/go/src go1.24.4 testing/.Tscip-go gomod github.com/golang/go/src go1.24.4 testing/T#) { |
| 237 | cache := NewCachescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/NewCache().().WithMaxSizescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#WithMaxSize().(NoMaxSizescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/NoMaxSize.) |
| 238 | cache.Setscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Set().("key", 1) |
| 239 | value, ok := cache.Getscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Get().("key") |
| 240 | if !ok { |
| 241 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("expected key to exist") |
| 242 | } |
| 243 | if value != 1 { |
| 244 | t.Errorfscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Errorf().("expected: %v, but got: %v", 1, value) |
| 245 | } |
| 246 | cache.Setscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Set().("key", 2.1) |
| 247 | value, ok = cache.Getscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Get().("key") |
| 248 | if !ok { |
| 249 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("expected key to exist") |
| 250 | } |
| 251 | if value != 2.1 { |
| 252 | t.Errorfscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Errorf().("expected: %v, but got: %v", 2.1, value) |
| 253 | } |
| 254 | } |
| 255 | |
| 256 | func TestCache_SetGetBoolscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/TestCache_SetGetBool().(t *testingscip-go gomod github.com/golang/go/src go1.24.4 testing/.Tscip-go gomod github.com/golang/go/src go1.24.4 testing/T#) { |
| 257 | cache := NewCachescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/NewCache().().WithMaxSizescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#WithMaxSize().(NoMaxSizescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/NoMaxSize.) |
| 258 | cache.Setscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Set().("key", true) |
| 259 | value, ok := cache.Getscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Get().("key") |
| 260 | if !ok { |
| 261 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("expected key to exist") |
| 262 | } |
| 263 | if value != true { |
| 264 | t.Errorfscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Errorf().("expected: %v, but got: %v", true, value) |
| 265 | } |
| 266 | } |
| 267 | |
| 268 | func TestCache_SetGetByteSlicescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/TestCache_SetGetByteSlice().(t *testingscip-go gomod github.com/golang/go/src go1.24.4 testing/.Tscip-go gomod github.com/golang/go/src go1.24.4 testing/T#) { |
| 269 | cache := NewCachescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/NewCache().().WithMaxSizescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#WithMaxSize().(NoMaxSizescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/NoMaxSize.) |
| 270 | cache.Setscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Set().("key", []byte("hey")) |
| 271 | value, ok := cache.Getscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Get().("key") |
| 272 | if !ok { |
| 273 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("expected key to exist") |
| 274 | } |
| 275 | if bytesscip-go gomod github.com/golang/go/src go1.24.4 bytes/.Comparescip-go gomod github.com/golang/go/src go1.24.4 bytes/Compare().(value.([]byte), []byte("hey")) != 0 { |
| 276 | t.Errorfscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Errorf().("expected: %v, but got: %v", []byte("hey"), value) |
| 277 | } |
| 278 | } |
| 279 | |
| 280 | func TestCache_SetGetStringSlicescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/TestCache_SetGetStringSlice().(t *testingscip-go gomod github.com/golang/go/src go1.24.4 testing/.Tscip-go gomod github.com/golang/go/src go1.24.4 testing/T#) { |
| 281 | cache := NewCachescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/NewCache().().WithMaxSizescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#WithMaxSize().(NoMaxSizescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/NoMaxSize.) |
| 282 | cache.Setscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Set().("key", []string{"john", "doe"}) |
| 283 | value, ok := cache.Getscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Get().("key") |
| 284 | if !ok { |
| 285 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("expected key to exist") |
| 286 | } |
| 287 | if value.([]string)[0] != "john" { |
| 288 | t.Errorfscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Errorf().("expected: %v, but got: %v", "john", value) |
| 289 | } |
| 290 | if value.([]string)[1] != "doe" { |
| 291 | t.Errorfscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Errorf().("expected: %v, but got: %v", "doe", value) |
| 292 | } |
| 293 | } |
| 294 | |
| 295 | func TestCache_SetGetStructscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/TestCache_SetGetStruct().(t *testingscip-go gomod github.com/golang/go/src go1.24.4 testing/.Tscip-go gomod github.com/golang/go/src go1.24.4 testing/T#) { |
| 296 | cache := NewCachescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/NewCache().().WithMaxSizescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#WithMaxSize().(NoMaxSizescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/NoMaxSize.) |
| 297 | type Custom struct { |
| 298 | Int int |
| 299 | Uint uint |
| 300 | Float32 float32 |
| 301 | String string |
| 302 | Strings []string |
| 303 | Nested struct { |
| 304 | String string |
| 305 | } |
| 306 | } |
| 307 | cache.Setscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Set().("key", Custom{ |
| 308 | Int: 111, |
| 309 | Uint: 222, |
| 310 | Float32: 123.456, |
| 311 | String: "hello", |
| 312 | Strings: []string{"s1", "s2"}, |
| 313 | Nested: struct{ String string }{String: "nested field"}, |
| 314 | }) |
| 315 | value, ok := cache.Getscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Get().("key") |
| 316 | if !ok { |
| 317 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("expected key to exist") |
| 318 | } |
| 319 | if ExpectedValue := 111; value.(Custom).Int != ExpectedValue { |
| 320 | t.Errorfscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Errorf().("expected: %v, but got: %v", ExpectedValue, value) |
| 321 | } |
| 322 | if ExpectedValue := uint(222); value.(Custom).Uint != ExpectedValue { |
| 323 | t.Errorfscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Errorf().("expected: %v, but got: %v", ExpectedValue, value) |
| 324 | } |
| 325 | if ExpectedValue := float32(123.456); value.(Custom).Float32 != ExpectedValue { |
| 326 | t.Errorfscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Errorf().("expected: %v, but got: %v", ExpectedValue, value) |
| 327 | } |
| 328 | if ExpectedValue := "hello"; value.(Custom).String != ExpectedValue { |
| 329 | t.Errorfscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Errorf().("expected: %v, but got: %v", ExpectedValue, value) |
| 330 | } |
| 331 | if ExpectedValue := "s1"; value.(Custom).Strings[0] != ExpectedValue { |
| 332 | t.Errorfscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Errorf().("expected: %v, but got: %v", ExpectedValue, value) |
| 333 | } |
| 334 | if ExpectedValue := "s2"; value.(Custom).Strings[1] != ExpectedValue { |
| 335 | t.Errorfscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Errorf().("expected: %v, but got: %v", ExpectedValue, value) |
| 336 | } |
| 337 | if ExpectedValue := "nested field"; value.(Custom).Nested.String != ExpectedValue { |
| 338 | t.Errorfscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Errorf().("expected: %v, but got: %v", ExpectedValue, value) |
| 339 | } |
| 340 | } |
| 341 | |
| 342 | func TestCache_SetAllscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/TestCache_SetAll().(t *testingscip-go gomod github.com/golang/go/src go1.24.4 testing/.Tscip-go gomod github.com/golang/go/src go1.24.4 testing/T#) { |
| 343 | cache := NewCachescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/NewCache().().WithMaxSizescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#WithMaxSize().(NoMaxSizescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/NoMaxSize.) |
| 344 | cache.SetAllscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#SetAll().(map[string]any{"k1": "v1", "k2": "v2"}) |
| 345 | value, ok := cache.Getscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Get().("k1") |
| 346 | if !ok { |
| 347 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("expected key to exist") |
| 348 | } |
| 349 | if value != "v1" { |
| 350 | t.Errorfscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Errorf().("expected: %s, but got: %s", "v1", value) |
| 351 | } |
| 352 | value, ok = cache.Getscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Get().("k2") |
| 353 | if !ok { |
| 354 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("expected key to exist") |
| 355 | } |
| 356 | if value != "v2" { |
| 357 | t.Errorfscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Errorf().("expected: %s, but got: %s", "v2", value) |
| 358 | } |
| 359 | cache.SetAllscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#SetAll().(map[string]any{"k1": "updated"}) |
| 360 | value, ok = cache.Getscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Get().("k1") |
| 361 | if !ok { |
| 362 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("expected key to exist") |
| 363 | } |
| 364 | if value != "updated" { |
| 365 | t.Errorfscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Errorf().("expected: %s, but got: %s", "updated", value) |
| 366 | } |
| 367 | } |
| 368 | |
| 369 | func TestCache_SetWithTTLscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/TestCache_SetWithTTL().(t *testingscip-go gomod github.com/golang/go/src go1.24.4 testing/.Tscip-go gomod github.com/golang/go/src go1.24.4 testing/T#) { |
| 370 | cache := NewCachescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/NewCache().().WithMaxSizescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#WithMaxSize().(NoMaxSizescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/NoMaxSize.) |
| 371 | cache.SetWithTTLscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#SetWithTTL().("key", "value", NoExpirationscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/NoExpiration.) |
| 372 | value, ok := cache.Getscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Get().("key") |
| 373 | if !ok { |
| 374 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("expected key to exist") |
| 375 | } |
| 376 | if value != "value" { |
| 377 | t.Errorfscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Errorf().("expected: %s, but got: %s", "value", value) |
| 378 | } |
| 379 | } |
| 380 | |
| 381 | func TestCache_SetWithTTLWhenTTLIsNegativescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/TestCache_SetWithTTLWhenTTLIsNegative().(t *testingscip-go gomod github.com/golang/go/src go1.24.4 testing/.Tscip-go gomod github.com/golang/go/src go1.24.4 testing/T#) { |
| 382 | cache := NewCachescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/NewCache().().WithMaxSizescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#WithMaxSize().(NoMaxSizescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/NoMaxSize.) |
| 383 | cache.SetWithTTLscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#SetWithTTL().("key", "value", -12345) |
| 384 | _, ok := cache.Getscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Get().("key") |
| 385 | if ok { |
| 386 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("expected key to not exist, because there's no point in creating a cache entry that has a negative TTL") |
| 387 | } |
| 388 | } |
| 389 | |
| 390 | func TestCache_SetWithTTLWhenTTLIsZeroscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/TestCache_SetWithTTLWhenTTLIsZero().(t *testingscip-go gomod github.com/golang/go/src go1.24.4 testing/.Tscip-go gomod github.com/golang/go/src go1.24.4 testing/T#) { |
| 391 | cache := NewCachescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/NewCache().().WithMaxSizescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#WithMaxSize().(NoMaxSizescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/NoMaxSize.) |
| 392 | cache.SetWithTTLscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#SetWithTTL().("key", "value", 0) |
| 393 | _, ok := cache.Getscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Get().("key") |
| 394 | if ok { |
| 395 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("expected key to not exist, because there's no point in creating a cache entry that has a TTL of 0") |
| 396 | } |
| 397 | } |
| 398 | |
| 399 | func TestCache_SetWithTTLWhenTTLIsZeroAndEntryAlreadyExistsscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/TestCache_SetWithTTLWhenTTLIsZeroAndEntryAlreadyExists().(t *testingscip-go gomod github.com/golang/go/src go1.24.4 testing/.Tscip-go gomod github.com/golang/go/src go1.24.4 testing/T#) { |
| 400 | cache := NewCachescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/NewCache().().WithMaxSizescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#WithMaxSize().(NoMaxSizescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/NoMaxSize.) |
| 401 | cache.SetWithTTLscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#SetWithTTL().("key", "value", NoExpirationscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/NoExpiration.) |
| 402 | cache.SetWithTTLscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#SetWithTTL().("key", "value", 0) |
| 403 | _, ok := cache.Getscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Get().("key") |
| 404 | if ok { |
| 405 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("expected key to not exist, because there's the entry was created with a TTL of 0, so it should have been deleted immediately") |
| 406 | } |
| 407 | } |
| 408 | |
| 409 | func TestCache_EvictionsRespectMaxSizescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/TestCache_EvictionsRespectMaxSize().(t *testingscip-go gomod github.com/golang/go/src go1.24.4 testing/.Tscip-go gomod github.com/golang/go/src go1.24.4 testing/T#) { |
| 410 | cache := NewCachescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/NewCache().().WithMaxSizescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#WithMaxSize().(5) |
| 411 | for n := 0; n < 10; n++ { |
| 412 | cache.Setscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Set().(fmtscip-go gomod github.com/golang/go/src go1.24.4 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.24.4 fmt/Sprintf().("test_%d", n), []byte("value")) |
| 413 | } |
| 414 | count := cache.Countscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Count().() |
| 415 | if count > 5 { |
| 416 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("Max size was set to 5, but the cache size reached a size of", count) |
| 417 | } |
| 418 | } |
| 419 | |
| 420 | func TestCache_EvictionsWithFIFOscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/TestCache_EvictionsWithFIFO().(t *testingscip-go gomod github.com/golang/go/src go1.24.4 testing/.Tscip-go gomod github.com/golang/go/src go1.24.4 testing/T#) { |
| 421 | cache := NewCachescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/NewCache().().WithMaxSizescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#WithMaxSize().(3).WithEvictionPolicyscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#WithEvictionPolicy().(FirstInFirstOutscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/FirstInFirstOut.) |
| 422 | |
| 423 | cache.Setscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Set().("1", []byte("value")) |
| 424 | cache.Setscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Set().("2", []byte("value")) |
| 425 | cache.Setscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Set().("3", []byte("value")) |
| 426 | _, _ = cache.Getscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Get().("1") |
| 427 | cache.Setscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Set().("4", []byte("value")) |
| 428 | _, ok := cache.Getscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Get().("1") |
| 429 | if ok { |
| 430 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("expected key 1 to have been removed, because FIFO") |
| 431 | } |
| 432 | } |
| 433 | |
| 434 | func TestCache_EvictionsWithLRUscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/TestCache_EvictionsWithLRU().(t *testingscip-go gomod github.com/golang/go/src go1.24.4 testing/.Tscip-go gomod github.com/golang/go/src go1.24.4 testing/T#) { |
| 435 | cache := NewCachescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/NewCache().().WithMaxSizescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#WithMaxSize().(3).WithEvictionPolicyscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#WithEvictionPolicy().(LeastRecentlyUsedscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/LeastRecentlyUsed.) |
| 436 | |
| 437 | cache.Setscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Set().("1", []byte("value")) |
| 438 | cache.Setscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Set().("2", []byte("value")) |
| 439 | cache.Setscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Set().("3", []byte("value")) |
| 440 | _, _ = cache.Getscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Get().("1") |
| 441 | cache.Setscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Set().("4", []byte("value")) |
| 442 | |
| 443 | _, ok := cache.Getscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Get().("1") |
| 444 | if !ok { |
| 445 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("expected key 1 to still exist, because LRU") |
| 446 | } |
| 447 | } |
| 448 | |
| 449 | func TestCache_HeadToTailSimplescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/TestCache_HeadToTailSimple().(t *testingscip-go gomod github.com/golang/go/src go1.24.4 testing/.Tscip-go gomod github.com/golang/go/src go1.24.4 testing/T#) { |
| 450 | cache := NewCachescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/NewCache().().WithMaxSizescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#WithMaxSize().(3) |
| 451 | cache.Setscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Set().("1", "1") |
| 452 | if cache.tailscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#tail..Keyscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#Key. != "1" && cache.headscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#head..Keyscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#Key. != "1" { |
| 453 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("expected tail=1 and head=1") |
| 454 | } |
| 455 | cache.Setscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Set().("2", "2") |
| 456 | if cache.tailscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#tail..Keyscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#Key. != "1" && cache.headscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#head..Keyscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#Key. != "2" { |
| 457 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("expected tail=1 and head=2") |
| 458 | } |
| 459 | cache.Setscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Set().("3", "3") |
| 460 | if cache.tailscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#tail..Keyscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#Key. != "1" && cache.headscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#head..Keyscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#Key. != "3" { |
| 461 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("expected tail=1 and head=4") |
| 462 | } |
| 463 | cache.Setscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Set().("4", "4") |
| 464 | if cache.tailscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#tail..Keyscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#Key. != "2" && cache.headscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#head..Keyscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#Key. != "4" { |
| 465 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("expected tail=2 and head=4") |
| 466 | } |
| 467 | cache.Setscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Set().("5", "5") |
| 468 | if cache.tailscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#tail..Keyscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#Key. != "3" && cache.headscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#head..Keyscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#Key. != "5" { |
| 469 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("expected tail=3 and head=5") |
| 470 | } |
| 471 | } |
| 472 | |
| 473 | func TestCache_HeadTailWorksWithFIFOscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/TestCache_HeadTailWorksWithFIFO().(t *testingscip-go gomod github.com/golang/go/src go1.24.4 testing/.Tscip-go gomod github.com/golang/go/src go1.24.4 testing/T#) { |
| 474 | cache := NewCachescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/NewCache().().WithMaxSizescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#WithMaxSize().(3).WithEvictionPolicyscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#WithEvictionPolicy().(FirstInFirstOutscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/FirstInFirstOut.) |
| 475 | |
| 476 | if cache.tailscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#tail. != nil { |
| 477 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("cache tail should have been nil") |
| 478 | } |
| 479 | if cache.headscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#head. != nil { |
| 480 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("cache head should have been nil") |
| 481 | } |
| 482 | |
| 483 | cache.Setscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Set().("1", []byte("value")) |
| 484 | |
| 485 | // (head) 1 (tail) |
| 486 | if cache.tailscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#tail. == nil || cache.tailscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#tail..Keyscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#Key. != "1" { |
| 487 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("cache tail should have been entry with key 1") |
| 488 | } |
| 489 | if cache.headscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#head. == nil || cache.headscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#head..Keyscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#Key. != "1" { |
| 490 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("cache head should have been entry with key 1") |
| 491 | } |
| 492 | |
| 493 | cache.Setscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Set().("2", []byte("value")) |
| 494 | |
| 495 | // (head) 2 - 1 (tail) |
| 496 | if cache.tailscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#tail. == nil || cache.tailscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#tail..Keyscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#Key. != "1" { |
| 497 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("cache tail should have been the entry with key 1") |
| 498 | } |
| 499 | if cache.headscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#head. == nil || cache.headscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#head..Keyscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#Key. != "2" { |
| 500 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("cache head should have been the entry with key 2") |
| 501 | } |
| 502 | if cache.headscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#head..nextscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#next..Keyscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#Key. != "1" { |
| 503 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("The entry key next to the cache head should have been 1") |
| 504 | } |
| 505 | if cache.headscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#head..previousscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#previous. != nil { |
| 506 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("The cache head should not have a previous node") |
| 507 | } |
| 508 | if cache.tailscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#tail..previousscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#previous..Keyscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#Key. != "2" { |
| 509 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("The entry key previous to the cache tail should have been 2") |
| 510 | } |
| 511 | if cache.tailscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#tail..nextscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#next. != nil { |
| 512 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("The cache tail should not have a next node") |
| 513 | } |
| 514 | |
| 515 | cache.Setscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Set().("3", []byte("value")) |
| 516 | |
| 517 | // (head) 3 - 2 - 1 (tail) |
| 518 | if cache.tailscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#tail. == nil || cache.tailscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#tail..Keyscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#Key. != "1" { |
| 519 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("cache tail should have been the entry with key 1") |
| 520 | } |
| 521 | if cache.tailscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#tail..previousscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#previous..Keyscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#Key. != "2" { |
| 522 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("The entry key previous to the cache tail should have been 2") |
| 523 | } |
| 524 | if cache.tailscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#tail..nextscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#next. != nil { |
| 525 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("The cache tail should not have a next node") |
| 526 | } |
| 527 | if cache.headscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#head. == nil || cache.headscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#head..Keyscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#Key. != "3" { |
| 528 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("cache head should have been the entry with key 3") |
| 529 | } |
| 530 | if cache.headscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#head..nextscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#next..Keyscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#Key. != "2" { |
| 531 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("The entry key next to the cache head should have been 2") |
| 532 | } |
| 533 | if cache.headscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#head..previousscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#previous. != nil { |
| 534 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("The cache head should not have a previous node") |
| 535 | } |
| 536 | if cache.headscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#head..nextscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#next..previousscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#previous..Keyscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#Key. != "3" { |
| 537 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("The head's next node should have its previous node pointing to the cache head") |
| 538 | } |
| 539 | if cache.headscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#head..nextscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#next..nextscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#next..Keyscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#Key. != "1" { |
| 540 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("The head's next node should have its next node pointing to the cache tail") |
| 541 | } |
| 542 | |
| 543 | // Get the first entry. This doesn't change anything for FIFO, but for LRU, it would mean that retrieved entry |
| 544 | // wouldn't be evicted since it was recently accessed. Basically, we just want to make sure that FIFO works |
| 545 | // as intended (i.e. not like LRU) |
| 546 | _, _ = cache.Getscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Get().("1") |
| 547 | |
| 548 | cache.Setscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Set().("4", []byte("value")) |
| 549 | |
| 550 | // (head) 4 - 3 - 2 (tail) |
| 551 | _, ok := cache.Getscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Get().("1") |
| 552 | if ok { |
| 553 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("expected key 1 to have been removed, because FIFO") |
| 554 | } |
| 555 | if cache.tailscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#tail. == nil || cache.tailscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#tail..Keyscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#Key. != "2" { |
| 556 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("cache tail should have been the entry with key 2") |
| 557 | } |
| 558 | if cache.tailscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#tail..previousscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#previous..Keyscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#Key. != "3" { |
| 559 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("The entry key previous to the cache tail should have been 3") |
| 560 | } |
| 561 | if cache.tailscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#tail..nextscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#next. != nil { |
| 562 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("The cache tail should not have a next node") |
| 563 | } |
| 564 | if cache.headscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#head. == nil || cache.headscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#head..Keyscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#Key. != "4" { |
| 565 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("cache head should have been the entry with key 4") |
| 566 | } |
| 567 | if cache.headscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#head..nextscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#next..Keyscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#Key. != "3" { |
| 568 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("The entry key next to the cache head should have been 3") |
| 569 | } |
| 570 | if cache.headscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#head..previousscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#previous. != nil { |
| 571 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("The cache head should not have a previous node") |
| 572 | } |
| 573 | if cache.headscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#head..nextscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#next..previousscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#previous..Keyscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#Key. != "4" { |
| 574 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("The head's next node should have its previous node pointing to the cache head") |
| 575 | } |
| 576 | if cache.headscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#head..nextscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#next..nextscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#next..Keyscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#Key. != "2" { |
| 577 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("The head's next node should have its next node pointing to the cache tail") |
| 578 | } |
| 579 | } |
| 580 | |
| 581 | func TestCache_HeadTailWorksWithLRUscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/TestCache_HeadTailWorksWithLRU().(t *testingscip-go gomod github.com/golang/go/src go1.24.4 testing/.Tscip-go gomod github.com/golang/go/src go1.24.4 testing/T#) { |
| 582 | cache := NewCachescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/NewCache().().WithMaxSizescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#WithMaxSize().(3).WithEvictionPolicyscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#WithEvictionPolicy().(LeastRecentlyUsedscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/LeastRecentlyUsed.) |
| 583 | |
| 584 | if cache.tailscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#tail. != nil { |
| 585 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("cache tail should have been nil") |
| 586 | } |
| 587 | if cache.headscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#head. != nil { |
| 588 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("cache head should have been nil") |
| 589 | } |
| 590 | |
| 591 | cache.Setscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Set().("1", []byte("value")) |
| 592 | |
| 593 | // (head) 1 (tail) |
| 594 | if cache.tailscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#tail. == nil || cache.tailscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#tail..Keyscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#Key. != "1" { |
| 595 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("cache tail should have been entry with key 1") |
| 596 | } |
| 597 | if cache.headscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#head. == nil || cache.headscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#head..Keyscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#Key. != "1" { |
| 598 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("cache head should have been entry with key 1") |
| 599 | } |
| 600 | |
| 601 | cache.Setscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Set().("2", []byte("value")) |
| 602 | |
| 603 | // (head) 2 - 1 (tail) |
| 604 | if cache.tailscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#tail. == nil || cache.tailscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#tail..Keyscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#Key. != "1" { |
| 605 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("cache tail should have been the entry with key 1") |
| 606 | } |
| 607 | if cache.headscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#head. == nil || cache.headscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#head..Keyscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#Key. != "2" { |
| 608 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("cache head should have been the entry with key 2") |
| 609 | } |
| 610 | if cache.headscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#head..nextscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#next..Keyscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#Key. != "1" { |
| 611 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("The entry key next to the cache head should have been 1") |
| 612 | } |
| 613 | if cache.headscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#head..previousscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#previous. != nil { |
| 614 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("The cache head should not have a previous node") |
| 615 | } |
| 616 | if cache.tailscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#tail..previousscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#previous..Keyscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#Key. != "2" { |
| 617 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("The entry key previous to the cache tail should have been 2") |
| 618 | } |
| 619 | if cache.tailscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#tail..nextscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#next. != nil { |
| 620 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("The cache tail should not have a next node") |
| 621 | } |
| 622 | |
| 623 | cache.Setscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Set().("3", []byte("value")) |
| 624 | |
| 625 | // (head) 3 - 2 - 1 (tail) |
| 626 | if cache.tailscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#tail. == nil || cache.tailscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#tail..Keyscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#Key. != "1" { |
| 627 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("cache tail should have been the entry with key 1") |
| 628 | } |
| 629 | if cache.tailscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#tail..previousscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#previous..Keyscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#Key. != "2" { |
| 630 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("The entry key previous to the cache tail should have been 2") |
| 631 | } |
| 632 | if cache.tailscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#tail..nextscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#next. != nil { |
| 633 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("The cache tail should not have a next node") |
| 634 | } |
| 635 | if cache.headscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#head. == nil || cache.headscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#head..Keyscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#Key. != "3" { |
| 636 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("cache head should have been the entry with key 3") |
| 637 | } |
| 638 | if cache.headscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#head..nextscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#next..Keyscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#Key. != "2" { |
| 639 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("The entry key next to the cache head should have been 2") |
| 640 | } |
| 641 | if cache.headscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#head..previousscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#previous. != nil { |
| 642 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("The cache head should not have a previous node") |
| 643 | } |
| 644 | if cache.headscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#head..nextscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#next..previousscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#previous..Keyscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#Key. != "3" { |
| 645 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("The head's next node should have its previous node pointing to the cache head") |
| 646 | } |
| 647 | if cache.headscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#head..nextscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#next..nextscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#next..Keyscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#Key. != "1" { |
| 648 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("The head's next node should have its next node pointing to the cache tail") |
| 649 | } |
| 650 | |
| 651 | // Because we're using a LRU cache, this should cause 1 to get moved back to the head, thus |
| 652 | // moving it from the tail. |
| 653 | // In other words, because we retrieved the key 1 here, this is no longer the least recently used cache entry, |
| 654 | // which means it will not be evicted during the next insertion. |
| 655 | _, _ = cache.Getscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Get().("1") |
| 656 | |
| 657 | // (head) 1 - 3 - 2 (tail) (This updated because LRU) |
| 658 | cache.Setscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Set().("4", []byte("value")) |
| 659 | |
| 660 | // (head) 4 - 1 - 3 (tail) |
| 661 | if cache.tailscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#tail. == nil || cache.tailscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#tail..Keyscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#Key. != "3" { |
| 662 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("cache tail should have been the entry with key 3") |
| 663 | } |
| 664 | if cache.tailscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#tail..previousscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#previous..Keyscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#Key. != "1" { |
| 665 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("The entry key previous to the cache tail should have been 1") |
| 666 | } |
| 667 | if cache.tailscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#tail..nextscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#next. != nil { |
| 668 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("The cache tail should not have a next node") |
| 669 | } |
| 670 | if cache.headscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#head. == nil || cache.headscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#head..Keyscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#Key. != "4" { |
| 671 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("cache head should have been the entry with key 4") |
| 672 | } |
| 673 | if cache.headscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#head..nextscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#next..Keyscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#Key. != "1" { |
| 674 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("The entry key next to the cache head should have been 1") |
| 675 | } |
| 676 | if cache.headscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#head..previousscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#previous. != nil { |
| 677 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("The cache head should not have a previous node") |
| 678 | } |
| 679 | if cache.headscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#head..nextscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#next..previousscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#previous..Keyscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#Key. != cache.headscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#head..Keyscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#Key. { |
| 680 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("The head's next node should have its previous node pointing to the cache head") |
| 681 | } |
| 682 | if cache.headscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#head..nextscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#next..nextscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#next..Keyscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#Key. != cache.tailscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#tail..Keyscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#Key. { |
| 683 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("Should be able to walk from head to tail") |
| 684 | } |
| 685 | if cache.tailscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#tail..previousscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#previous..previousscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#previous. != cache.headscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#head. { |
| 686 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("Should be able to walk from tail to head") |
| 687 | } |
| 688 | |
| 689 | _, ok := cache.Getscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Get().("1") |
| 690 | if !ok { |
| 691 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("expected key 1 to still exist, because LRU") |
| 692 | } |
| 693 | } |
| 694 | |
| 695 | func TestCache_HeadStaysTheSameIfCallRepeatedlyscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/TestCache_HeadStaysTheSameIfCallRepeatedly().(t *testingscip-go gomod github.com/golang/go/src go1.24.4 testing/.Tscip-go gomod github.com/golang/go/src go1.24.4 testing/T#) { |
| 696 | cache := NewCachescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/NewCache().().WithEvictionPolicyscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#WithEvictionPolicy().(LeastRecentlyUsedscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/LeastRecentlyUsed.).WithMaxSizescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#WithMaxSize().(10) |
| 697 | cache.Setscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Set().("1", "1") |
| 698 | if cache.tailscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#tail..Keyscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#Key. != "1" && cache.headscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#head..Keyscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#Key. != "1" { |
| 699 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("expected tail=1 and head=1") |
| 700 | } |
| 701 | cache.Setscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Set().("1", "1") |
| 702 | if cache.tailscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#tail..Keyscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#Key. != "1" && cache.headscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#head..Keyscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#Key. != "1" { |
| 703 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("expected tail=1 and head=1") |
| 704 | } |
| 705 | cache.Getscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Get().("1") |
| 706 | if cache.tailscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#tail..Keyscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#Key. != "1" && cache.headscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#head..Keyscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#Key. != "1" { |
| 707 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("expected tail=1 and head=1") |
| 708 | } |
| 709 | cache.Getscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Get().("1") |
| 710 | if cache.tailscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#tail..Keyscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#Key. != "1" && cache.headscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#head..Keyscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#Key. != "1" { |
| 711 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("expected tail=1 and head=1") |
| 712 | } |
| 713 | } |
| 714 | |
| 715 | func TestCache_Deletescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/TestCache_Delete().(t *testingscip-go gomod github.com/golang/go/src go1.24.4 testing/.Tscip-go gomod github.com/golang/go/src go1.24.4 testing/T#) { |
| 716 | cache := NewCachescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/NewCache().() |
| 717 | |
| 718 | if cache.tailscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#tail. != nil { |
| 719 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("cache tail should have been nil") |
| 720 | } |
| 721 | if cache.headscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#head. != nil { |
| 722 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("cache head should have been nil") |
| 723 | } |
| 724 | |
| 725 | cache.Setscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Set().("1", "hey") |
| 726 | cache.Setscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Set().("2", []byte("sup")) |
| 727 | cache.Setscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Set().("3", 123456) |
| 728 | |
| 729 | // (head) 3 - 2 - 1 (tail) |
| 730 | if cache.tailscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#tail..Keyscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#Key. != "1" { |
| 731 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("cache tail should have been the entry with key 1") |
| 732 | } |
| 733 | if cache.headscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#head..Keyscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#Key. != "3" { |
| 734 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("cache head should have been the entry with key 3") |
| 735 | } |
| 736 | |
| 737 | cache.Deletescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Delete().("2") |
| 738 | |
| 739 | // (head) 3 - 1 (tail) |
| 740 | if cache.tailscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#tail..Keyscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#Key. != "1" { |
| 741 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("cache tail should have been the entry with key 1") |
| 742 | } |
| 743 | if cache.headscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#head..Keyscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#Key. != "3" { |
| 744 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("cache head should have been the entry with key 3") |
| 745 | } |
| 746 | if cache.tailscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#tail..previousscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#previous..Keyscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#Key. != "3" { |
| 747 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("The entry key previous to the cache tail should have been 3") |
| 748 | } |
| 749 | if cache.headscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#head..nextscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#next..Keyscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#Key. != "1" { |
| 750 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("The entry key next to the cache tail should have been 1") |
| 751 | } |
| 752 | |
| 753 | cache.Deletescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Delete().("1") |
| 754 | |
| 755 | // (head) 3 (tail) |
| 756 | if cache.tailscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#tail..Keyscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#Key. != "3" { |
| 757 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("cache tail should have been the entry with key 3") |
| 758 | } |
| 759 | if cache.headscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#head..Keyscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#Key. != "3" { |
| 760 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("cache head should have been the entry with key 3") |
| 761 | } |
| 762 | |
| 763 | if cache.headscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#head. != cache.tailscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#tail. { |
| 764 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("There should only be one entry in the cache") |
| 765 | } |
| 766 | if cache.headscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#head..nextscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#next. != nil || cache.tailscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#tail..previousscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Entry#previous. != nil { |
| 767 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("Since head == tail, there should be no next/prev") |
| 768 | } |
| 769 | } |
| 770 | |
| 771 | func TestCache_DeleteAllscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/TestCache_DeleteAll().(t *testingscip-go gomod github.com/golang/go/src go1.24.4 testing/.Tscip-go gomod github.com/golang/go/src go1.24.4 testing/T#) { |
| 772 | cache := NewCachescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/NewCache().() |
| 773 | cache.Setscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Set().("1", []byte("1")) |
| 774 | cache.Setscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Set().("2", []byte("2")) |
| 775 | cache.Setscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Set().("3", []byte("3")) |
| 776 | if len(cache.GetByKeysscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#GetByKeys().([]string{"1", "2", "3"})) != 3 { |
| 777 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("Expected keys 1, 2 and 3 to exist") |
| 778 | } |
| 779 | numberOfDeletedKeys := cache.DeleteAllscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#DeleteAll().([]string{"1", "2", "3"}) |
| 780 | if numberOfDeletedKeys != 3 { |
| 781 | t.Errorfscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Errorf().("Expected 3 keys to have been deleted, but only %d were deleted", numberOfDeletedKeys) |
| 782 | } |
| 783 | } |
| 784 | |
| 785 | func TestCache_DeleteKeysByPatternscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/TestCache_DeleteKeysByPattern().(t *testingscip-go gomod github.com/golang/go/src go1.24.4 testing/.Tscip-go gomod github.com/golang/go/src go1.24.4 testing/T#) { |
| 786 | cache := NewCachescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/NewCache().() |
| 787 | cache.Setscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Set().("a1", []byte("v")) |
| 788 | cache.Setscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Set().("a2", []byte("v")) |
| 789 | cache.Setscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Set().("b1", []byte("v")) |
| 790 | if len(cache.GetByKeysscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#GetByKeys().([]string{"a1", "a2", "b1"})) != 3 { |
| 791 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("Expected keys 1, 2 and 3 to exist") |
| 792 | } |
| 793 | numberOfDeletedKeys := cache.DeleteKeysByPatternscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#DeleteKeysByPattern().("a*") |
| 794 | if numberOfDeletedKeys != 2 { |
| 795 | t.Errorfscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Errorf().("Expected 2 keys to have been deleted, but only %d were deleted", numberOfDeletedKeys) |
| 796 | } |
| 797 | if _, exists := cache.Getscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Get().("b1"); !exists { |
| 798 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("Expected key b1 to still exist") |
| 799 | } |
| 800 | } |
| 801 | |
| 802 | func TestCache_TTLscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/TestCache_TTL().(t *testingscip-go gomod github.com/golang/go/src go1.24.4 testing/.Tscip-go gomod github.com/golang/go/src go1.24.4 testing/T#) { |
| 803 | cache := NewCachescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/NewCache().() |
| 804 | ttl, err := cache.TTLscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#TTL().("key") |
| 805 | if err != ErrKeyDoesNotExistscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/ErrKeyDoesNotExist. { |
| 806 | t.Errorfscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Errorf().("expected %s, got %s", ErrKeyDoesNotExistscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/ErrKeyDoesNotExist., err) |
| 807 | } |
| 808 | cache.Setscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Set().("key", "value") |
| 809 | _, err = cache.TTLscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#TTL().("key") |
| 810 | if err != ErrKeyHasNoExpirationscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/ErrKeyHasNoExpiration. { |
| 811 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("Expected TTL on new key created using Set to have no expiration") |
| 812 | } |
| 813 | cache.SetWithTTLscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#SetWithTTL().("key", "value", timescip-go gomod github.com/golang/go/src go1.24.4 time/.Hourscip-go gomod github.com/golang/go/src go1.24.4 time/Hour.) |
| 814 | ttl, err = cache.TTLscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#TTL().("key") |
| 815 | if err != nil { |
| 816 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("Unexpected error") |
| 817 | } |
| 818 | if ttl.Minutesscip-go gomod github.com/golang/go/src go1.24.4 time/Duration#Minutes().() < 59 || ttl.Minutesscip-go gomod github.com/golang/go/src go1.24.4 time/Duration#Minutes().() > 60 { |
| 819 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("Expected the TTL to be almost an hour") |
| 820 | } |
| 821 | cache.SetWithTTLscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#SetWithTTL().("key", "value", 5*timescip-go gomod github.com/golang/go/src go1.24.4 time/.Millisecondscip-go gomod github.com/golang/go/src go1.24.4 time/Millisecond.) |
| 822 | timescip-go gomod github.com/golang/go/src go1.24.4 time/.Sleepscip-go gomod github.com/golang/go/src go1.24.4 time/Sleep().(6 * timescip-go gomod github.com/golang/go/src go1.24.4 time/.Millisecondscip-go gomod github.com/golang/go/src go1.24.4 time/Millisecond.) |
| 823 | ttl, err = cache.TTLscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#TTL().("key") |
| 824 | if err != ErrKeyDoesNotExistscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/ErrKeyDoesNotExist. { |
| 825 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("key should've expired, thus TTL should've returned ") |
| 826 | } |
| 827 | } |
| 828 | |
| 829 | func TestCache_Expirescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/TestCache_Expire().(t *testingscip-go gomod github.com/golang/go/src go1.24.4 testing/.Tscip-go gomod github.com/golang/go/src go1.24.4 testing/T#) { |
| 830 | cache := NewCachescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/NewCache().() |
| 831 | if cache.Expirescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Expire().("key-that-does-not-exist", timescip-go gomod github.com/golang/go/src go1.24.4 time/.Minutescip-go gomod github.com/golang/go/src go1.24.4 time/Minute.) { |
| 832 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("Expected Expire to return false, because the key used did not exist") |
| 833 | } |
| 834 | cache.Setscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Set().("key", "value") |
| 835 | _, err := cache.TTLscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#TTL().("key") |
| 836 | if err != ErrKeyHasNoExpirationscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/ErrKeyHasNoExpiration. { |
| 837 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("Expected TTL on new key created using Set to have no expiration") |
| 838 | } |
| 839 | if !cache.Expirescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Expire().("key", timescip-go gomod github.com/golang/go/src go1.24.4 time/.Hourscip-go gomod github.com/golang/go/src go1.24.4 time/Hour.) { |
| 840 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("Expected Expire to return true") |
| 841 | } |
| 842 | ttl, err := cache.TTLscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#TTL().("key") |
| 843 | if err != nil { |
| 844 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("Unexpected error") |
| 845 | } |
| 846 | if ttl.Minutesscip-go gomod github.com/golang/go/src go1.24.4 time/Duration#Minutes().() < 59 || ttl.Minutesscip-go gomod github.com/golang/go/src go1.24.4 time/Duration#Minutes().() > 60 { |
| 847 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("Expected the TTL to be almost an hour") |
| 848 | } |
| 849 | if !cache.Expirescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Expire().("key", 5*timescip-go gomod github.com/golang/go/src go1.24.4 time/.Millisecondscip-go gomod github.com/golang/go/src go1.24.4 time/Millisecond.) { |
| 850 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("Expected Expire to return true") |
| 851 | } |
| 852 | timescip-go gomod github.com/golang/go/src go1.24.4 time/.Sleepscip-go gomod github.com/golang/go/src go1.24.4 time/Sleep().(6 * timescip-go gomod github.com/golang/go/src go1.24.4 time/.Millisecondscip-go gomod github.com/golang/go/src go1.24.4 time/Millisecond.) |
| 853 | _, err = cache.TTLscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#TTL().("key") |
| 854 | if err != ErrKeyDoesNotExistscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/ErrKeyDoesNotExist. { |
| 855 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("key should've expired, thus TTL should've returned ErrKeyDoesNotExist") |
| 856 | } |
| 857 | if cache.Expirescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Expire().("key", timescip-go gomod github.com/golang/go/src go1.24.4 time/.Hourscip-go gomod github.com/golang/go/src go1.24.4 time/Hour.) { |
| 858 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("Expire should've returned false, because the key should've already expired, thus no longer exist") |
| 859 | } |
| 860 | cache.SetWithTTLscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#SetWithTTL().("key", "value", timescip-go gomod github.com/golang/go/src go1.24.4 time/.Hourscip-go gomod github.com/golang/go/src go1.24.4 time/Hour.) |
| 861 | if !cache.Expirescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Expire().("key", NoExpirationscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/NoExpiration.) { |
| 862 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("Expire should've returned true") |
| 863 | } |
| 864 | if _, err := cache.TTLscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#TTL().("key"); err != ErrKeyHasNoExpirationscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/ErrKeyHasNoExpiration. { |
| 865 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("TTL should've returned ErrKeyHasNoExpiration") |
| 866 | } |
| 867 | } |
| 868 | |
| 869 | func TestCache_Clearscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/TestCache_Clear().(t *testingscip-go gomod github.com/golang/go/src go1.24.4 testing/.Tscip-go gomod github.com/golang/go/src go1.24.4 testing/T#) { |
| 870 | cache := NewCachescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/NewCache().().WithMaxSizescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#WithMaxSize().(10) |
| 871 | cache.Setscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Set().("k1", "v1") |
| 872 | cache.Setscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Set().("k2", "v2") |
| 873 | cache.Setscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Set().("k3", "v3") |
| 874 | if cache.Countscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Count().() != 3 { |
| 875 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("expected cache size to be 3, got", cache.Countscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Count().()) |
| 876 | } |
| 877 | cache.Clearscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Clear().() |
| 878 | if cache.Countscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Count().() != 0 { |
| 879 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("expected cache to be empty") |
| 880 | } |
| 881 | if cache.memoryUsagescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#memoryUsage. != 0 { |
| 882 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("expected cache.memoryUsage to be 0") |
| 883 | } |
| 884 | } |
| 885 | |
| 886 | func TestCache_WithMaxSizescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/TestCache_WithMaxSize().(t *testingscip-go gomod github.com/golang/go/src go1.24.4 testing/.Tscip-go gomod github.com/golang/go/src go1.24.4 testing/T#) { |
| 887 | cache := NewCachescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/NewCache().().WithMaxSizescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#WithMaxSize().(1234) |
| 888 | if cache.MaxSizescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#MaxSize().() != 1234 { |
| 889 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("expected cache to have a maximum size of 1234") |
| 890 | } |
| 891 | } |
| 892 | |
| 893 | func TestCache_WithMaxSizeAndNegativeValuescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/TestCache_WithMaxSizeAndNegativeValue().(t *testingscip-go gomod github.com/golang/go/src go1.24.4 testing/.Tscip-go gomod github.com/golang/go/src go1.24.4 testing/T#) { |
| 894 | cache := NewCachescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/NewCache().().WithMaxSizescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#WithMaxSize().(-10) |
| 895 | if cache.MaxSizescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#MaxSize().() != NoMaxSizescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/NoMaxSize. { |
| 896 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("expected cache to have no maximum size") |
| 897 | } |
| 898 | } |
| 899 | |
| 900 | func TestCache_WithMaxMemoryUsagescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/TestCache_WithMaxMemoryUsage().(t *testingscip-go gomod github.com/golang/go/src go1.24.4 testing/.Tscip-go gomod github.com/golang/go/src go1.24.4 testing/T#) { |
| 901 | const ValueSize = Kilobytescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Kilobyte. |
| 902 | cache := NewCachescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/NewCache().().WithMaxSizescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#WithMaxSize().(0).WithMaxMemoryUsagescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#WithMaxMemoryUsage().(Kilobytescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Kilobyte. * 64) |
| 903 | for i := 0; i < 100; i++ { |
| 904 | cache.Setscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Set().(fmtscip-go gomod github.com/golang/go/src go1.24.4 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.24.4 fmt/Sprintf().("%d", i), stringsscip-go gomod github.com/golang/go/src go1.24.4 strings/.Repeatscip-go gomod github.com/golang/go/src go1.24.4 strings/Repeat().("0", ValueSize)) |
| 905 | } |
| 906 | if cache.MemoryUsagescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#MemoryUsage().()/1024 < 63 || cache.MemoryUsagescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#MemoryUsage().()/1024 > 65 { |
| 907 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("expected memoryUsage to be between 63KB and 64KB") |
| 908 | } |
| 909 | } |
| 910 | |
| 911 | func TestCache_WithMaxMemoryUsageWhenAddingAnEntryThatCausesMoreThanOneEvictionscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/TestCache_WithMaxMemoryUsageWhenAddingAnEntryThatCausesMoreThanOneEviction().(t *testingscip-go gomod github.com/golang/go/src go1.24.4 testing/.Tscip-go gomod github.com/golang/go/src go1.24.4 testing/T#) { |
| 912 | const ValueSize = Kilobytescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Kilobyte. |
| 913 | cache := NewCachescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/NewCache().().WithMaxSizescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#WithMaxSize().(0).WithMaxMemoryUsagescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#WithMaxMemoryUsage().(64 * Kilobytescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Kilobyte.) |
| 914 | for i := 0; i < 100; i++ { |
| 915 | cache.Setscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Set().(fmtscip-go gomod github.com/golang/go/src go1.24.4 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.24.4 fmt/Sprintf().("%d", i), stringsscip-go gomod github.com/golang/go/src go1.24.4 strings/.Repeatscip-go gomod github.com/golang/go/src go1.24.4 strings/Repeat().("0", ValueSize)) |
| 916 | } |
| 917 | if cache.MemoryUsagescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#MemoryUsage().()/1024 < 63 || cache.MemoryUsagescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#MemoryUsage().()/1024 > 65 { |
| 918 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("expected memoryUsage to be between 63KB and 64KB") |
| 919 | } |
| 920 | } |
| 921 | |
| 922 | func TestCache_WithMaxMemoryUsageAndNegativeValuescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/TestCache_WithMaxMemoryUsageAndNegativeValue().(t *testingscip-go gomod github.com/golang/go/src go1.24.4 testing/.Tscip-go gomod github.com/golang/go/src go1.24.4 testing/T#) { |
| 923 | cache := NewCachescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/NewCache().().WithMaxSizescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#WithMaxSize().(0).WithMaxMemoryUsagescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#WithMaxMemoryUsage().(-1234) |
| 924 | if cache.MaxMemoryUsagescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#MaxMemoryUsage().() != NoMaxMemoryUsagescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/NoMaxMemoryUsage. { |
| 925 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("attempting to set a negative max memory usage should force MaxMemoryUsage to NoMaxMemoryUsage") |
| 926 | } |
| 927 | } |
| 928 | |
| 929 | func TestCache_MemoryUsageAfterSet10000AndDelete5000scip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/TestCache_MemoryUsageAfterSet10000AndDelete5000().(t *testingscip-go gomod github.com/golang/go/src go1.24.4 testing/.Tscip-go gomod github.com/golang/go/src go1.24.4 testing/T#) { |
| 930 | const ValueSize = 64 |
| 931 | cache := NewCachescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/NewCache().().WithMaxSizescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#WithMaxSize().(10000).WithMaxMemoryUsagescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#WithMaxMemoryUsage().(Gigabytescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Gigabyte.) |
| 932 | for i := 0; i < cache.maxSizescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#maxSize.; i++ { |
| 933 | cache.Setscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Set().(fmtscip-go gomod github.com/golang/go/src go1.24.4 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.24.4 fmt/Sprintf().("%05d", i), stringsscip-go gomod github.com/golang/go/src go1.24.4 strings/.Repeatscip-go gomod github.com/golang/go/src go1.24.4 strings/Repeat().("0", ValueSize)) |
| 934 | } |
| 935 | memoryUsageBeforeDeleting := cache.MemoryUsagescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#MemoryUsage().() |
| 936 | for i := 0; i < cache.maxSizescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#maxSize./2; i++ { |
| 937 | key := fmtscip-go gomod github.com/golang/go/src go1.24.4 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.24.4 fmt/Sprintf().("%05d", i) |
| 938 | cache.Deletescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Delete().(key) |
| 939 | } |
| 940 | memoryUsageRatio := float32(cache.MemoryUsagescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#MemoryUsage().()) / float32(memoryUsageBeforeDeleting) |
| 941 | if memoryUsageRatio != 0.5 { |
| 942 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("Since half of the keys were deleted, the memoryUsage should've been half of what the memory usage was before beginning deletion") |
| 943 | } |
| 944 | } |
| 945 | |
| 946 | func TestCache_MemoryUsageIsReliablescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/TestCache_MemoryUsageIsReliable().(t *testingscip-go gomod github.com/golang/go/src go1.24.4 testing/.Tscip-go gomod github.com/golang/go/src go1.24.4 testing/T#) { |
| 947 | cache := NewCachescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/NewCache().().WithMaxMemoryUsagescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#WithMaxMemoryUsage().(Megabytescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Megabyte.) |
| 948 | previousCacheMemoryUsage := cache.MemoryUsagescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#MemoryUsage().() |
| 949 | if previousCacheMemoryUsage != 0 { |
| 950 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("cache.MemoryUsage() should've been 0") |
| 951 | } |
| 952 | cache.Setscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Set().("1", 1) |
| 953 | if cache.MemoryUsagescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#MemoryUsage().() <= previousCacheMemoryUsage { |
| 954 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("cache.MemoryUsage() should've increased") |
| 955 | } |
| 956 | previousCacheMemoryUsage = cache.MemoryUsagescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#MemoryUsage().() |
| 957 | cache.SetAllscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#SetAll().(map[string]any{"2": "2", "3": "3", "4": "4"}) |
| 958 | if cache.MemoryUsagescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#MemoryUsage().() <= previousCacheMemoryUsage { |
| 959 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("cache.MemoryUsage() should've increased") |
| 960 | } |
| 961 | previousCacheMemoryUsage = cache.MemoryUsagescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#MemoryUsage().() |
| 962 | cache.Deletescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Delete().("2") |
| 963 | if cache.MemoryUsagescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#MemoryUsage().() >= previousCacheMemoryUsage { |
| 964 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("cache.MemoryUsage() should've decreased") |
| 965 | } |
| 966 | previousCacheMemoryUsage = cache.MemoryUsagescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#MemoryUsage().() |
| 967 | cache.Setscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Set().("1", 1) |
| 968 | if cache.MemoryUsagescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#MemoryUsage().() != previousCacheMemoryUsage { |
| 969 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("cache.MemoryUsage() shouldn't have changed, because the entry didn't change") |
| 970 | } |
| 971 | previousCacheMemoryUsage = cache.MemoryUsagescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#MemoryUsage().() |
| 972 | cache.Deletescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Delete().("3") |
| 973 | if cache.MemoryUsagescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#MemoryUsage().() >= previousCacheMemoryUsage { |
| 974 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("cache.MemoryUsage() should've decreased") |
| 975 | } |
| 976 | previousCacheMemoryUsage = cache.MemoryUsagescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#MemoryUsage().() |
| 977 | cache.Deletescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Delete().("4") |
| 978 | if cache.MemoryUsagescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#MemoryUsage().() >= previousCacheMemoryUsage { |
| 979 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("cache.MemoryUsage() should've decreased") |
| 980 | } |
| 981 | previousCacheMemoryUsage = cache.MemoryUsagescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#MemoryUsage().() |
| 982 | cache.Deletescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Delete().("1") |
| 983 | if cache.MemoryUsagescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#MemoryUsage().() >= previousCacheMemoryUsage || cache.memoryUsagescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#memoryUsage. != 0 { |
| 984 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("cache.MemoryUsage() should've been 0") |
| 985 | } |
| 986 | previousCacheMemoryUsage = cache.MemoryUsagescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#MemoryUsage().() |
| 987 | cache.Setscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Set().("1", "v4lu3") |
| 988 | if cache.MemoryUsagescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#MemoryUsage().() <= previousCacheMemoryUsage { |
| 989 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("cache.MemoryUsage() should've increased") |
| 990 | } |
| 991 | previousCacheMemoryUsage = cache.MemoryUsagescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#MemoryUsage().() |
| 992 | cache.Setscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Set().("1", "value") |
| 993 | if cache.MemoryUsagescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#MemoryUsage().() != previousCacheMemoryUsage { |
| 994 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("cache.MemoryUsage() shouldn't have changed") |
| 995 | } |
| 996 | previousCacheMemoryUsage = cache.MemoryUsagescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#MemoryUsage().() |
| 997 | cache.Setscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Set().("1", true) |
| 998 | if cache.MemoryUsagescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#MemoryUsage().() >= previousCacheMemoryUsage { |
| 999 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("cache.MemoryUsage() should've decreased, because a bool uses less memory than a string") |
| 1000 | } |
| 1001 | } |
| 1002 | |
| 1003 | func TestCache_MemoryUsageAndMaxSizeIsReliablescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/TestCache_MemoryUsageAndMaxSizeIsReliable().(t *testingscip-go gomod github.com/golang/go/src go1.24.4 testing/.Tscip-go gomod github.com/golang/go/src go1.24.4 testing/T#) { |
| 1004 | cache := NewCachescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/NewCache().().WithMaxMemoryUsagescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#WithMaxMemoryUsage().(100 * Kilobytescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Kilobyte.).WithMaxSizescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#WithMaxSize().(1) |
| 1005 | randscip-go gomod github.com/golang/go/src go1.24.4 `math/rand`/.Seedscip-go gomod github.com/golang/go/src go1.24.4 `math/rand`/Seed().(timescip-go gomod github.com/golang/go/src go1.24.4 time/.Nowscip-go gomod github.com/golang/go/src go1.24.4 time/Now().().UnixNanoscip-go gomod github.com/golang/go/src go1.24.4 time/Time#UnixNano().()) |
| 1006 | for i := 0; i < 10000; i++ { |
| 1007 | if i%5 == 0 { |
| 1008 | cache.Setscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Set().(strconvscip-go gomod github.com/golang/go/src go1.24.4 strconv/.Itoascip-go gomod github.com/golang/go/src go1.24.4 strconv/Itoa().(randscip-go gomod github.com/golang/go/src go1.24.4 `math/rand`/.Intnscip-go gomod github.com/golang/go/src go1.24.4 `math/rand`/Intn().(10)), stringsscip-go gomod github.com/golang/go/src go1.24.4 strings/.Repeatscip-go gomod github.com/golang/go/src go1.24.4 strings/Repeat().("what", randscip-go gomod github.com/golang/go/src go1.24.4 `math/rand`/.Intnscip-go gomod github.com/golang/go/src go1.24.4 `math/rand`/Intn().(10000))) |
| 1009 | } else { |
| 1010 | cache.Setscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Set().(strconvscip-go gomod github.com/golang/go/src go1.24.4 strconv/.Itoascip-go gomod github.com/golang/go/src go1.24.4 strconv/Itoa().(randscip-go gomod github.com/golang/go/src go1.24.4 `math/rand`/.Intnscip-go gomod github.com/golang/go/src go1.24.4 `math/rand`/Intn().(10)), struct { |
| 1011 | m map[string]any |
| 1012 | s string |
| 1013 | }{ |
| 1014 | m: map[string]any{ |
| 1015 | "a": "b", |
| 1016 | stringsscip-go gomod github.com/golang/go/src go1.24.4 strings/.Repeatscip-go gomod github.com/golang/go/src go1.24.4 strings/Repeat().("b", randscip-go gomod github.com/golang/go/src go1.24.4 `math/rand`/.Intnscip-go gomod github.com/golang/go/src go1.24.4 `math/rand`/Intn().(1000)): map[string]string{ |
| 1017 | stringsscip-go gomod github.com/golang/go/src go1.24.4 strings/.Repeatscip-go gomod github.com/golang/go/src go1.24.4 strings/Repeat().("c", randscip-go gomod github.com/golang/go/src go1.24.4 `math/rand`/.Intnscip-go gomod github.com/golang/go/src go1.24.4 `math/rand`/Intn().(1000)): "d", |
| 1018 | }, |
| 1019 | }, |
| 1020 | s: stringsscip-go gomod github.com/golang/go/src go1.24.4 strings/.Repeatscip-go gomod github.com/golang/go/src go1.24.4 strings/Repeat().("e", randscip-go gomod github.com/golang/go/src go1.24.4 `math/rand`/.Intnscip-go gomod github.com/golang/go/src go1.24.4 `math/rand`/Intn().(1000)), |
| 1021 | }) |
| 1022 | } |
| 1023 | cache.Getscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Get().(strconvscip-go gomod github.com/golang/go/src go1.24.4 strconv/.Itoascip-go gomod github.com/golang/go/src go1.24.4 strconv/Itoa().(randscip-go gomod github.com/golang/go/src go1.24.4 `math/rand`/.Intnscip-go gomod github.com/golang/go/src go1.24.4 `math/rand`/Intn().(10))) |
| 1024 | if cache.MemoryUsagescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#MemoryUsage().() < 0 { |
| 1025 | t.Fatalscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Fatal().("cache.MemoryUsage() should never be negative") |
| 1026 | } |
| 1027 | } |
| 1028 | } |
| 1029 | |
| 1030 | func TestCache_WithDefaultTTLscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/TestCache_WithDefaultTTL().(t *testingscip-go gomod github.com/golang/go/src go1.24.4 testing/.Tscip-go gomod github.com/golang/go/src go1.24.4 testing/T#) { |
| 1031 | cache := NewCachescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/NewCache().().WithDefaultTTLscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#WithDefaultTTL().(5 * timescip-go gomod github.com/golang/go/src go1.24.4 time/.Millisecondscip-go gomod github.com/golang/go/src go1.24.4 time/Millisecond.) |
| 1032 | if cache.defaultTTLscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#defaultTTL. != 5*timescip-go gomod github.com/golang/go/src go1.24.4 time/.Millisecondscip-go gomod github.com/golang/go/src go1.24.4 time/Millisecond. { |
| 1033 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("expected defaultTTL to be 5ms") |
| 1034 | } |
| 1035 | cache.Setscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Set().("1", 1) |
| 1036 | cache.SetWithTTLscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#SetWithTTL().("2", 2, timescip-go gomod github.com/golang/go/src go1.24.4 time/.Hourscip-go gomod github.com/golang/go/src go1.24.4 time/Hour.) |
| 1037 | if cache.GetValuescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#GetValue().("1") == nil { |
| 1038 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("expected cache entry with key 1 to still exist") |
| 1039 | } |
| 1040 | if cache.GetValuescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#GetValue().("2") == nil { |
| 1041 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("expected cache entry with key 2 to still exist") |
| 1042 | } |
| 1043 | timescip-go gomod github.com/golang/go/src go1.24.4 time/.Sleepscip-go gomod github.com/golang/go/src go1.24.4 time/Sleep().(10 * timescip-go gomod github.com/golang/go/src go1.24.4 time/.Millisecondscip-go gomod github.com/golang/go/src go1.24.4 time/Millisecond.) |
| 1044 | if cache.GetValuescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#GetValue().("1") != nil { |
| 1045 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("expected cache entry with key 1 to have expired") |
| 1046 | } |
| 1047 | if cache.GetValuescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#GetValue().("2") == nil { |
| 1048 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("expected cache entry with key 2 to still exist") |
| 1049 | } |
| 1050 | } |
| 1051 | |
| 1052 | func TestCache_WithForceNilInterfaceOnNilPointerscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/TestCache_WithForceNilInterfaceOnNilPointer().(t *testingscip-go gomod github.com/golang/go/src go1.24.4 testing/.Tscip-go gomod github.com/golang/go/src go1.24.4 testing/T#) { |
| 1053 | type Struct struct{} |
| 1054 | cache := NewCachescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/NewCache().().WithForceNilInterfaceOnNilPointerscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#WithForceNilInterfaceOnNilPointer().(true) |
| 1055 | cache.Setscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Set().("key", (*Struct)(nil)) |
| 1056 | if value, exists := cache.Getscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Get().("key"); !exists { |
| 1057 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("expected key to exist") |
| 1058 | } else { |
| 1059 | if value != nil { |
| 1060 | // the value is not nil, because cache.Get returns an interface{} (any), and the type of that interface is not nil |
| 1061 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("value should be nil") |
| 1062 | } |
| 1063 | } |
| 1064 | |
| 1065 | cache.Clearscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Clear().() |
| 1066 | |
| 1067 | cache = cache.WithForceNilInterfaceOnNilPointerscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#WithForceNilInterfaceOnNilPointer().(false) |
| 1068 | cache.Setscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Set().("key", (*Struct)(nil)) |
| 1069 | if value, exists := cache.Getscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Get().("key"); !exists { |
| 1070 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("expected key to exist") |
| 1071 | } else { |
| 1072 | if value == nil { |
| 1073 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("value should be not be nil, because the type of the interface is not nil") |
| 1074 | } |
| 1075 | if value.(*Struct) != nil { |
| 1076 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("casted value should be nil") |
| 1077 | } |
| 1078 | } |
| 1079 | } |
| 1080 | |
| 1081 | func TestEvictionWhenThereIsNothingToEvictscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/TestEvictionWhenThereIsNothingToEvict().(t *testingscip-go gomod github.com/golang/go/src go1.24.4 testing/.Tscip-go gomod github.com/golang/go/src go1.24.4 testing/T#) { |
| 1082 | cache := NewCachescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/NewCache().() |
| 1083 | cache.evictscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#evict().() |
| 1084 | cache.evictscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#evict().() |
| 1085 | cache.evictscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#evict().() |
| 1086 | } |
| 1087 | |
| 1088 | func TestCachescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/TestCache().(t *testingscip-go gomod github.com/golang/go/src go1.24.4 testing/.Tscip-go gomod github.com/golang/go/src go1.24.4 testing/T#) { |
| 1089 | cache := NewCachescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/NewCache().().WithMaxSizescip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#WithMaxSize().(3).WithEvictionPolicyscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#WithEvictionPolicy().(LeastRecentlyUsedscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/LeastRecentlyUsed.) |
| 1090 | cache.Setscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Set().("1", 1) |
| 1091 | cache.Setscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Set().("2", 2) |
| 1092 | cache.Setscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Set().("3", 3) |
| 1093 | cache.Setscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Set().("4", 4) |
| 1094 | if _, ok := cache.Getscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Get().("4"); !ok { |
| 1095 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("expected 4 to exist") |
| 1096 | } |
| 1097 | if _, ok := cache.Getscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Get().("3"); !ok { |
| 1098 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("expected 3 to exist") |
| 1099 | } |
| 1100 | if _, ok := cache.Getscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Get().("2"); !ok { |
| 1101 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("expected 2 to exist") |
| 1102 | } |
| 1103 | if _, ok := cache.Getscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Get().("1"); ok { |
| 1104 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("expected 1 to have been evicted") |
| 1105 | } |
| 1106 | cache.Setscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Set().("5", 5) |
| 1107 | if _, ok := cache.Getscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Get().("1"); ok { |
| 1108 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("expected 1 to have been evicted") |
| 1109 | } |
| 1110 | if _, ok := cache.Getscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Get().("2"); !ok { |
| 1111 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("expected 2 to exist") |
| 1112 | } |
| 1113 | if _, ok := cache.Getscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Get().("3"); !ok { |
| 1114 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("expected 3 to exist") |
| 1115 | } |
| 1116 | if _, ok := cache.Getscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Get().("4"); ok { |
| 1117 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("expected 4 to have been evicted") |
| 1118 | } |
| 1119 | if _, ok := cache.Getscip-go gomod github.com/TwiN/gocache/v2 . `github.com/TwiN/gocache/v2`/Cache#Get().("5"); !ok { |
| 1120 | t.Errorscip-go gomod github.com/golang/go/src go1.24.4 testing/common#Error().("expected 5 to exist") |
| 1121 | } |
| 1122 | } |