Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add GetWithExpirationUpdate #96

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

sbabiv
Copy link

@sbabiv sbabiv commented Feb 18, 2019

In many cases, it is convenient to get items with an updated cache lifetime.

  • GetWithExpirationUpdate - returns item and updates its cache expiration time

@mrbenosborne
Copy link

Hi @sbabiv,

This repository seems to have gone stale and I am going to keep the go-cache running, I have added your PR if you are interested.

https://github.com/mrbenosborne/go-cache/pull/1

Copy link

@paddlesteamer paddlesteamer left a comment

Choose a reason for hiding this comment

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

I think it is problematic. I'm worried about this (edge) case:

  1. we get the item, check the expiration, it is almost expired but not expired yet
  2. we do read unlock
  3. onEvicted wins the race condition and do something because it thinks the item is expired
  4. then we do write lock and reset the item

so it's not atomic. It may cause problems when it's used with user-provided onEvicted function.

I think to complete this completely the items should have their own mutexes and the changes inside of the items (like change in Expiration) shouldn't be considered in cache's write lock scope.

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.

3 participants