We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
According to the docs of the Set() method:
If an item associated with the provided key already exists, the new item overwrites the existing one.
However, if I try to set an item that already exists but has an expired TTL and delete all expired, the newly set item also gets deleted:
package main import ( "fmt" "time" "github.com/jellydator/ttlcache/v3" ) func main() { cache := ttlcache.New[string]( ttlcache.WithTTL[string, string](1 * time.Second), ) cache.Set("foo", "bar", ttlcache.DefaultTTL) fmt.Printf("first: %s\n", cache.Keys()) time.Sleep(2 * time.Second) fmt.Printf("after 2s: %s\n", cache.Keys()) cache.DeleteExpired() fmt.Printf("after delete: %s\n", cache.Keys()) cache.Set("baz", "qux", ttlcache.DefaultTTL) fmt.Printf("new: %s\n", cache.Keys()) time.Sleep(2 * time.Second) fmt.Printf("after 2s: %s\n", cache.Keys()) cache.Set("baz", "qum", ttlcache.DefaultTTL) cache.DeleteExpired() fmt.Printf("after set and delete: %s\n", cache.Keys()) }
Output:
first: [foo] after 2s: [foo] after delete: [] new: [baz] after 2s: [baz] after set and delete: []
I would expect the replaced item to have new TTL and not get deleted by DeleteExpired() call.
The text was updated successfully, but these errors were encountered:
Thanks for reporting this @vsavicks. We'll try to have it fixed soon.
Sorry, something went wrong.
just to provide some infomation.
I can't reproduce it at:
go version go1.23.5 darwin/arm64 github.com/jellydator/ttlcache/[email protected]
same code. but the output is:
first: [foo] after 2s: [] after delete: [] new: [baz] after 2s: [] after set and delete: [baz]
No branches or pull requests
According to the docs of the Set() method:
However, if I try to set an item that already exists but has an expired TTL and delete all expired, the newly set item also gets deleted:
Output:
I would expect the replaced item to have new TTL and not get deleted by DeleteExpired() call.
The text was updated successfully, but these errors were encountered: