MCPcopy Create free account
hub / github.com/patrickmn/go-cache / DeleteExpired

Method DeleteExpired

cache.go:931–948  ·  view source on GitHub ↗

Delete all expired items from the cache.

()

Source from the content-addressed store, hash-verified

929
930// Delete all expired items from the cache.
931func (c *cache) DeleteExpired() {
932 var evictedItems []keyAndValue
933 now := time.Now().UnixNano()
934 c.mu.Lock()
935 for k, v := range c.items {
936 // "Inlining" of expired
937 if v.Expiration > 0 && now > v.Expiration {
938 ov, evicted := c.delete(k)
939 if evicted {
940 evictedItems = append(evictedItems, keyAndValue{k, ov})
941 }
942 }
943 }
944 c.mu.Unlock()
945 for _, v := range evictedItems {
946 c.onEvicted(v.key, v.value)
947 }
948}
949
950// Sets an (optional) function that is called with the key and value when an
951// item is evicted from the cache. (Including when it is deleted manually, but

Callers 2

RunMethod · 0.45

Calls 1

deleteMethod · 0.95

Tested by 1