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

Set without expanding the Expire time #115

Closed
R4wm opened this issue Oct 25, 2023 · 3 comments
Closed

Set without expanding the Expire time #115

R4wm opened this issue Oct 25, 2023 · 3 comments

Comments

@R4wm
Copy link

R4wm commented Oct 25, 2023

Its not clear to me how to ".Set()" and not start the expire time over again.
Can someone point to reference or doc or advise ?

@davseby
Copy link
Contributor

davseby commented Oct 26, 2023

I think it's not possible. As a workaround, you could get the item and reset it with the modified ttl value.

var ttl time.Duration = cache.DefaultTTL

if previousItem := cache.Get(key); previousItem != nil {
      ttl = previousItem.ExpiresAt().Sub(time.Now())
}

cache.Set(key, value, ttl)

@swithek
Copy link
Contributor

swithek commented Oct 31, 2023

At present not updating an existing expiration time isn't possible, though it might a good feature for one of the future versions. We could add a new ttlcache.PreviousTTL option that would indicate that the previous TTL should be set after an update.

@swithek
Copy link
Contributor

swithek commented Feb 19, 2024

Implemented in #121

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants