MCPcopy
hub / github.com/coocood/freecache / TestExpire

Function TestExpire

cache_test.go:389–407  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

387}
388
389func TestExpire(t *testing.T) {
390 cache := NewCache(1024)
391 key := []byte("abcd")
392 val := []byte("efgh")
393 err := cache.Set(key, val, 1)
394 if err != nil {
395 t.Error("err should be nil")
396 }
397 time.Sleep(time.Second)
398 val, err = cache.Get(key)
399 if err == nil {
400 t.Fatal("key should be expired", string(val))
401 }
402
403 cache.ResetStatistics()
404 if cache.ExpiredCount() != 0 {
405 t.Error("expired count should be zero.")
406 }
407}
408
409func TestTTL(t *testing.T) {
410 t.Run("with no expire key", testTTLWithNoExpireKey)

Callers

nothing calls this directly

Calls 5

SetMethod · 0.95
GetMethod · 0.95
ResetStatisticsMethod · 0.95
ExpiredCountMethod · 0.95
NewCacheFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…