Delete from the cache on Get if the item expired (to trigger onEvicted)#75
Open
fdurand wants to merge 2 commits intopatrickmn:masterfrom
Open
Delete from the cache on Get if the item expired (to trigger onEvicted)#75fdurand wants to merge 2 commits intopatrickmn:masterfrom
fdurand wants to merge 2 commits intopatrickmn:masterfrom
Conversation
moadqassem
reviewed
Jan 4, 2018
| if item.Expiration > 0 { | ||
| if time.Now().UnixNano() > item.Expiration { | ||
| c.mu.RUnlock() | ||
| c.Delete(k) |
There was a problem hiding this comment.
What about adding this change also in the GetWithExpiration https://github.com/patrickmn/go-cache/pull/75/files#diff-56ffa6659747ba7a23d2b5597a4cda5dR143 ?
There was a problem hiding this comment.
I think you'll only want to call Delete if the cache has an eviction function.
|
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. |
|
Any updates on this PR? |
Repository owner
deleted a comment from
pablodz
Jan 8, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When we Get from the cache and if the item expired then Delete it to be sure that onEvicted is triggered.