diff --git a/cache.go b/cache.go index 2648ee0..c0ffa5d 100644 --- a/cache.go +++ b/cache.go @@ -65,9 +65,7 @@ func NewCache[K comparable, V any](c Config[K, V]) *Cache[K, V] { capacity: c.Capacity, } - cache.expirePolicy = expire.NewPolicy[K, V](func(n *node.Node[K, V]) { - cache.hashmap.EvictNode(n) - }) + cache.expirePolicy = expire.NewPolicy[K, V]() if c.StatsEnabled { cache.stats = stats.New() } diff --git a/internal/expire/policy.go b/internal/expire/policy.go index 2f8db35..6b8249e 100644 --- a/internal/expire/policy.go +++ b/internal/expire/policy.go @@ -74,16 +74,14 @@ func (b *bucket[K, V]) clear() { } type Policy[K comparable, V any] struct { - removeNode func(n *node.Node[K, V]) buckets [numberOfBuckets]bucket[K, V] expires *swiss.Map[*node.Node[K, V], struct{}] currentBucketID int } -func NewPolicy[K comparable, V any](removeNode func(n *node.Node[K, V])) *Policy[K, V] { +func NewPolicy[K comparable, V any]() *Policy[K, V] { p := &Policy[K, V]{ - removeNode: removeNode, - expires: swiss.NewMap[*node.Node[K, V], struct{}](mapSize), + expires: swiss.NewMap[*node.Node[K, V], struct{}](mapSize), } for i := 0; i < numberOfBuckets; i++ { @@ -139,7 +137,6 @@ func (p *Policy[K, V]) expireBucket(expired []*node.Node[K, V], bucketID int, no if now > b.lastTime { b.m.Iter(func(n *node.Node[K, V], _ struct{}) (stop bool) { p.expires.Delete(n) - p.removeNode(n) expired = append(expired, n) return false })