Skip to content

Conversation

@fdurand
Copy link

@fdurand fdurand commented Jan 3, 2018

When we Get from the cache and if the item expired then Delete it to be sure that onEvicted is triggered.

if item.Expiration > 0 {
if time.Now().UnixNano() > item.Expiration {
c.mu.RUnlock()
c.Delete(k)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about adding this change also in the GetWithExpiration https://github.com/patrickmn/go-cache/pull/75/files#diff-56ffa6659747ba7a23d2b5597a4cda5dR143 ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you'll only want to call Delete if the cache has an eviction function.

@aapolkovsky
Copy link

This will strongly affect on Get operation performance, because mutex will be locked for RW-access (another concurrent read operations will be also locked). Nevertheless, janitor will also lock cache while deleting other expired items.

@ekinanp
Copy link

ekinanp commented Mar 9, 2019

Any updates on this PR?

Repository owner deleted a comment from pablodz Jan 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants