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

Refactor DeleteExpired for safer behavior #60

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

AxelPrel
Copy link

  • make sure that expManager queue is not empty before popping, which can happen if an explicit delete happens while DeleteExpired releases the lock.

  • evict() now returns shouldContinue instead of a shouldBreak to simplify the loop.

@AxelPrel
Copy link
Author

it might also fix #59

- make sure that expManager queue is not empty before popping,
  which can happen if an explicit delete happens while DeleteExpired
  releases the lock.

- evict()  now returns shouldContinue instead of a shouldBreak to
  simplify the loop.
Copy link

codecov bot commented Jun 28, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (2601bb0) to head (a613de3).

Current head a613de3 differs from pull request most recent head f59f96f

Please upload reports for the commit f59f96f to get more accurate results.

Additional details and impacted files
@@            Coverage Diff            @@
##              main       #60   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           11        11           
  Lines          527       523    -4     
=========================================
- Hits           527       523    -4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

cache.go Outdated
Comment on lines 53 to 54
//Print tries to make a readable log of the item

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you remove these lines?

return false
}
key, expiration := c.expManager.pop()
if nowFunc().After(expiration) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think better to use expired than this because a Expired method already has checking expiration logic.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code was meant to avoid an extra cache.Get(). Also, if the cache already had deleted the item, Expired() was not callable. However, your approach is more maintainable, since if you edit the way Expired() works you need to edit this code as well. So what should I do about this change ?

@gonejack
Copy link

I don't think this would fix #59 as there are no limitation or scale down operations on capacity of expirationManager.queue or expirationManager.map

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 this pull request may close these issues.

3 participants