Repository navigation
Lightweight synchronous post-removal observer for future::Cache #606
javaquasar
started this conversation in
Ideas
Replies: 1 comment
|
A clean draft implementation is now available in #607. It contains only the public API, implementation, example, and focused tests; the contract remains open for maintainer feedback. |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Summary
Would the project be open to a lightweight synchronous post-removal observer for
moka::future::Cache?The existing eviction-listener APIs are the right choice when removal work needs asynchronous
execution or per-key serialization. Some applications, however, only need to publish a small
accounting record into their own bounded nonblocking queue after an entry has been logically
removed. For that narrower use case, enabling an eviction listener also enables listener-only
per-key locking and creates listener futures.
I have a tested prototype of a separate
CacheBuilder::post_removal_observerAPI and would likemaintainer feedback on the contract before opening an implementation PR.
Motivating use case
A cache user maintains external accounting derived from removal events. The callback itself does
not perform cleanup, I/O, or backpressure-sensitive work. It only attempts a nonblocking send into
a caller-owned bounded queue:
The caller owns queue capacity, overflow handling, reconciliation, draining, and shutdown. Moka
would only deliver the removal observation.
Proposed contract
The prototype is intentionally narrower than an eviction listener:
future::Cache, where avoiding listener futures and thelistener-only
KeyLockMapmatters.Arc<K>, clonedV, andRemovalCause.Explicit,Replaced,Expired, andSizeremovals after logical removal.cache.
first.
existing circuit-breaker policy. An observer call already running concurrently may still finish.
listener lifecycle.
run_pending_tasksmakes cache-maintenance removals observable, but does not wait for work thatthe observer publishes outside Moka.
This is not intended to replace the eviction listener. Applications that need asynchronous work,
per-key serialization, or Moka-managed cancellation recovery should continue to use the existing
listener API.
Prototype allocation evidence
The benchmark starts every sample in a fresh release process, rotates the mode/operation order,
and runs five samples for each pair. Relative to notification-off, the median allocation counts
were:
Median gross allocated bytes changed by:
This benchmark is evidence about allocation ownership, not a claim that elapsed time improves by a
corresponding amount.
The prototype, benchmark source, raw CSV, environment metadata, and checksums are available in the
fork branch:
javaquasar/moka@v0.12.16...hydracache/post-removal-observer-upstream-prep
Validation completed
The prototype currently has 18 focused observer tests covering:
RemovalCausevariants;remove, single/all/predicate invalidation, TTL, TTI, and weighted capacity eviction;All-feature, future-only, integration, documentation, strict Clippy, formatting, packaging, MSRV,
cross-compile, Loom, Kani, and Trybuild checks pass on the fork. The Miri workflow reproduces an
existing sync-only
timer_wheel_panic_test/parking_lotfutex failure; the failing stack does notcontain the observer or
future::Cachecode.Questions for maintainers
existing eviction-listener API?
post_removal_observeran appropriate name, and should the first version remain scoped tofuture::Cache?should coexistence be disallowed?
run_pending_taskssemantics consistent with theguarantees you want to preserve?
I am happy to reshape the API and split the implementation into the form maintainers prefer before
opening the PR.
All reactions