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

How do I freshen the TTL of already inserted entry? #19

Open
vi opened this issue Jan 30, 2020 · 3 comments
Open

How do I freshen the TTL of already inserted entry? #19

vi opened this issue Jan 30, 2020 · 3 comments

Comments

@vi
Copy link

vi commented Jan 30, 2020

How do I prevent actively used TtlCache entry from being expired and run its Drop::drop?


Update: looks like remove + insert works. Maybe explicit cache.refresh(&key) would be more readable?

@stusmall
Copy link
Owner

I've been using remove + insert but refresh would be a good addition. I'll add that.

@mooreniemi
Copy link

mooreniemi commented Jun 9, 2021

I was curious about this too; if you do remove can't this cause callers to have a cache miss until your insert logic finishes? Maybe this is ok if there's a RwLock surrounding.

@mooreniemi
Copy link

mooreniemi commented Jun 9, 2021

Alternatively, can there be a way to bump the ttl value by a potentially new set amount? This way you can do get_mut and update your cache entry if needed, and just extend the ttl rather than full remove/insert. (Maybe this is what you had in mind above.)

Edit: Sorry I wasn't really using my brain. It's just a map so I can just insert again with my updated ttl.

/// Sets the value of the entry, and returns the entry's old value

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

No branches or pull requests

3 participants