Add before_clean callback on bucket expiry (#140)#177
Merged
Conversation
Contributor
epinault
commented
Mar 27, 2026
- Accept optional :before_clean option in Hammer.ETS and Hammer.Atomic
- Callback receives algorithm atom and list of normalized expired entries
- Supports function/2 and {module, function, extra_args} MFA form
- Errors in callback are rescued/caught with a warning log; entries are still deleted to prevent unbounded memory growth
- Zero performance impact when not configured: existing select_delete / foldl+delete paths are preserved
- Add select_expired/1, delete_expired/2, normalize_expired/1 to all 4 ETS algorithm modules
- Add normalize_entry/2 to all 3 Atomic algorithm modules
- Add tests for all algorithms on both backends covering: correct algorithm atom and entries, callback raises, no-op when nothing expired, and MFA tuple form
- Accept optional :before_clean option in Hammer.ETS and Hammer.Atomic
- Callback receives algorithm atom and list of normalized expired entries
- Supports function/2 and {module, function, extra_args} MFA form
- Errors in callback are rescued/caught with a warning log; entries are
still deleted to prevent unbounded memory growth
- Zero performance impact when not configured: existing select_delete /
foldl+delete paths are preserved
- Add select_expired/1, delete_expired/2, normalize_expired/1 to all 4
ETS algorithm modules
- Add normalize_entry/2 to all 3 Atomic algorithm modules
- Add tests for all algorithms on both backends covering: correct
algorithm atom and entries, callback raises, no-op when nothing
expired, and MFA tuple form
jfayad
approved these changes
Mar 28, 2026
|
The overall implementation LGTM, I'm wondering though if it can't be more DRY as I see a lot of similar functions being rewritten across modules. Thanks for the PR |
- Extract shared invoke_before_clean/3, delete_expired/2, and @type before_clean into Hammer.CleanUtils - Consolidate 6 clean functions in Hammer.Atomic into 2 with a maybe_invoke_before_clean helper - Remove identical delete_expired/2 from all 4 ETS algorithm modules - Extract shared test helpers (eventually, CallbackHandler) into test/support
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.