Skip to content

Add before_clean callback on bucket expiry (#140)#177

Merged
epinault merged 2 commits intomasterfrom
before-clean-callback
Mar 30, 2026
Merged

Add before_clean callback on bucket expiry (#140)#177
epinault merged 2 commits intomasterfrom
before-clean-callback

Conversation

@epinault
Copy link
Copy Markdown
Contributor

  • 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
Copy link
Copy Markdown

jfayad commented 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
@epinault epinault merged commit 54162ab into master Mar 30, 2026
9 checks passed
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.

2 participants