Skip to content
New issue

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

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

Already on GitHub? # to your account

Addition of AddWithTtl to Expirable cache #175

Open
irenarindos opened this issue Mar 26, 2024 · 1 comment
Open

Addition of AddWithTtl to Expirable cache #175

irenarindos opened this issue Mar 26, 2024 · 1 comment

Comments

@irenarindos
Copy link
Collaborator

I'd like to propose adding the ability to have a per-key TTL to the Expirable implementation. This would accept a time.Duration and set the ExpiresAt of the LRU entry to the passed duration. Passing a value <= 0 would result in turning expiring off, as is the case when setting the TTL for a new Expirable cache.

// AddWithTtl creates an entry with the provided TTL, overriding the cache-level TTL
func (c *LRU[K, V]) AddWithTtl(key K, value V, t time.Duration) (evicted bool) 

The existing Add method would remain unchanged and would use the cache's TTL value.

I'm opening this issue to start a discussion about this design and will open a PR after discussion- tagging @mgaffney @jefferai @paskal for feedback.

@paskal
Copy link
Contributor

paskal commented Mar 26, 2024

I am not sure it's comparable with the current cleanup mechanism. Will new method work with it or you would need some other cleanup?

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants