diff --git a/2q.go b/2q.go index 5e00d9a..d0166cd 100644 --- a/2q.go +++ b/2q.go @@ -171,6 +171,11 @@ func (c *TwoQueueCache[K, V]) Len() int { return c.recent.Len() + c.frequent.Len() } +// Cap returns the capacity of the cache +func (c *TwoQueueCache[K, V]) Cap() int { + return c.size +} + // Keys returns a slice of the keys in the cache. // The frequently used keys are first in the returned slice. func (c *TwoQueueCache[K, V]) Keys() []K { diff --git a/2q_test.go b/2q_test.go index 0b979df..8889ffc 100644 --- a/2q_test.go +++ b/2q_test.go @@ -230,6 +230,9 @@ func Test2Q(t *testing.T) { if l.Len() != 128 { t.Fatalf("bad len: %v", l.Len()) } + if l.Cap() != 128 { + t.Fatalf("expect %d, but %d", 128, l.Cap()) + } for i, k := range l.Keys() { if v, ok := l.Get(k); !ok || v != k || v != i+128 { diff --git a/arc/arc.go b/arc/arc.go index 4d8bba3..5b6f4e0 100644 --- a/arc/arc.go +++ b/arc/arc.go @@ -204,7 +204,7 @@ func (c *ARCCache[K, V]) Len() int { // Cap returns the capacity of cache func (c *ARCCache[K, V]) Cap() int { - return c.Cap() + return c.size } // Keys returns all the cached keys