23
func TestTTLBasic(t *testing.T) {
24
ttl := NewTTL(5*time.Second, 1*time.Millisecond)
25
testCacheBasic(ttl, t)
28
func TestTTLConcurrent(t *testing.T) {
29
ttl := NewTTL(5*time.Second, 1*time.Second)
30
testCacheConcurrent(ttl, t)
33
func TestTTLExpiration(t *testing.T) {
34
ttl := NewTTL(5*time.Second, 0).(*ttlCache)
35
testCacheExpiration(ttl, ttl.evictExpired, t)
38
func TestTTLEvicter(t *testing.T) {
39
ttl := NewTTL(5*time.Second, 1*time.Millisecond)
43
func TestTTLEvictExpired(t *testing.T) {
44
ttl := NewTTL(5*time.Second, 0).(*ttlCache)
45
testCacheEvictExpired(ttl, t)
48
type callbackRecorder struct {
52
func (c *callbackRecorder) callback(key, value any) {
53
atomic.AddInt64(&c.callbacks, 1)
56
func TestTTLEvictionCallback(t *testing.T) {
57
c := &callbackRecorder{callbacks: 0}
58
ttl := NewTTLWithCallback(50*time.Millisecond, time.Millisecond, c.callback)
60
if atomic.LoadInt64(&c.callbacks) != 1 {
61
t.Errorf("evictExpired() => failed to invoke EvictionCallback: got %d callbacks, wanted 1", c.callbacks)
65
func TestTTLFinalizer(t *testing.T) {
66
ttl := NewTTL(5*time.Second, 1*time.Millisecond).(*ttlWrapper)
67
testCacheFinalizer(&ttl.evicterTerminated)
70
func BenchmarkTTLGet(b *testing.B) {
71
c := NewTTL(5*time.Minute, 1*time.Minute)
72
benchmarkCacheGet(c, b)
75
func BenchmarkTTLGetConcurrent(b *testing.B) {
76
c := NewTTL(5*time.Minute, 1*time.Minute)
77
benchmarkCacheGetConcurrent(c, b)
80
func BenchmarkTTLSet(b *testing.B) {
81
c := NewTTL(5*time.Minute, 1*time.Minute)
82
benchmarkCacheSet(c, b)
85
func BenchmarkTTLSetConcurrent(b *testing.B) {
86
c := NewTTL(5*time.Minute, 1*time.Minute)
87
benchmarkCacheSetConcurrent(c, b)
90
func BenchmarkTTLGetSetConcurrent(b *testing.B) {
91
c := NewTTL(5*time.Minute, 1*time.Minute)
92
benchmarkCacheGetSetConcurrent(c, b)
95
func BenchmarkTTLSetRemove(b *testing.B) {
96
c := NewTTL(5*time.Minute, 1*time.Minute)
97
benchmarkCacheSetRemove(c, b)