Closed cmsong-shina closed 11 months ago
You can use OnEviction method. DeleteExpired
is the only method that uses the EvictionReasonExpired
reason, which can be used to identify deleted items.
Something like this:
// c is a Cache instance.
cleanup := c.OnEviction(func(ctx context.Context, er ttlcache.EvictionReason, i *ttlcache.Item[string, string]) {
if er != ttlcache.EvictionReasonExpired {
return
}
// do something with the expired item.
})
// once we no longer need to track the evicted items, we can remove the callback function.
defer cleanup()
c.DeleteExpired()
There is a way to do it.
I know I can clear expired elements via the
.DeleteExpired()
method. My question is, is there a way to get the expired elements?Right now I am using it as a vendor module by adding the following method.
Do you think this is a safe and reasonable implementation, and if so, can we add it to the official API?