MCPcopy
hub / github.com/go-gorm/gorm / TestLRUInvalidateAndEvict

Function TestLRUInvalidateAndEvict

tests/lru_test.go:367–396  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

365}
366
367func TestLRUInvalidateAndEvict(t *testing.T) {
368 var evicted int
369 lc := lru.NewLRU(-1, func(_, _ string) { evicted++ }, 0)
370
371 lc.Add("key1", "val1")
372 lc.Add("key2", "val2")
373
374 val, ok := lc.Get("key1")
375 if !ok {
376 t.Fatalf("should be true")
377 }
378 if val != "val1" {
379 t.Fatalf("value differs from expected")
380 }
381 if evicted != 0 {
382 t.Fatalf("value differs from expected")
383 }
384
385 lc.Remove("key1")
386 if evicted != 1 {
387 t.Fatalf("value differs from expected")
388 }
389 val, ok = lc.Get("key1")
390 if val != "" {
391 t.Fatalf("should be empty")
392 }
393 if ok {
394 t.Fatalf("should be false")
395 }
396}
397
398func TestLoadingExpired(t *testing.T) {
399 lc := lru.NewLRU[string, string](0, nil, time.Millisecond*5)

Callers

nothing calls this directly

Calls 4

NewLRUFunction · 0.92
AddMethod · 0.80
GetMethod · 0.65
RemoveMethod · 0.45

Tested by

no test coverage detected