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

Slow expiration key clearing #47

Closed
RelicOfTesla opened this issue Apr 12, 2024 · 7 comments · Fixed by #48
Closed

Slow expiration key clearing #47

RelicOfTesla opened this issue Apr 12, 2024 · 7 comments · Fixed by #48

Comments

@RelicOfTesla
Copy link

Don't use full keys scan........

@Code-Hex
Copy link
Owner

@RelicOfTesla Do you have any plans?

@Code-Hex
Copy link
Owner

@RelicOfTesla I have released v1.4.0.

@RelicOfTesla
Copy link
Author

RelicOfTesla commented Apr 13, 2024

@Code-Hex Still scanning with all key??? You only need to check if the top items in the priority queue have expired.

@Code-Hex
Copy link
Owner

Code-Hex commented Apr 13, 2024

@RelicOfTesla not all scanned

go-generics-cache/cache.go

Lines 231 to 251 in 5303a9a

evict := func() bool {
key := c.expManager.pop()
// if is expired, delete it and return nil instead
item, ok := c.cache.Get(key)
if ok {
if item.Expired() {
c.cache.Delete(key)
return false
}
c.expManager.update(key, item.Expiration)
}
return true
}
for i := 0; i < l; i++ {
c.mu.Lock()
shouldBreak := evict()
c.mu.Unlock()
if shouldBreak {
break
}

@RelicOfTesla
Copy link
Author

RelicOfTesla commented Apr 13, 2024

Well, I read it wrong, but you only deleted one element ??

@Code-Hex
Copy link
Owner

@RelicOfTesla No, Please read my test cases. I tested them

#48

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 a pull request may close this issue.

2 participants