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

Function TestTouch

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

Source from the content-addressed store, hash-verified

538}
539
540func TestTouch(t *testing.T) {
541 cache := NewCache(1024)
542 key1 := []byte("abcd")
543 val1 := []byte("efgh")
544 key2 := []byte("ijkl")
545 val2 := []byte("mnop")
546 err := cache.Set(key1, val1, 1)
547 if err != nil {
548 t.Error("err should be nil", err.Error())
549 }
550 err = cache.Set(key2, val2, 1)
551 if err != nil {
552 t.Error("err should be nil", err.Error())
553 }
554 if touched := cache.TouchedCount(); touched != 0 {
555 t.Fatalf("touched count should be 0, but %d returned", touched)
556 }
557 err = cache.Touch(key1, 2)
558 if err != nil {
559 t.Error("err should be nil", err.Error())
560 }
561 time.Sleep(time.Second)
562 ttl, err := cache.TTL(key1)
563 if err != nil {
564 t.Error("err should be nil", err.Error())
565 }
566 if ttl != 1 {
567 t.Fatalf("ttl should be 1, but %d returned", ttl)
568 }
569 if touched := cache.TouchedCount(); touched != 1 {
570 t.Fatalf("touched count should be 1, but %d returned", touched)
571 }
572 err = cache.Touch(key2, 2)
573 if err != ErrNotFound {
574 t.Error("error should be ErrNotFound after expiring")
575 }
576 if touched := cache.TouchedCount(); touched != 1 {
577 t.Fatalf("touched count should be 1, but %d returned", touched)
578 }
579}
580
581func TestAverageAccessTimeWhenUpdateInplace(t *testing.T) {
582 cache := NewCache(1024)

Callers

nothing calls this directly

Calls 5

SetMethod · 0.95
TouchedCountMethod · 0.95
TouchMethod · 0.95
TTLMethod · 0.95
NewCacheFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…