moka
A fast and concurrent cache library inspired by Java Caffeine
0.12.16
114M downloads/mo
#742 most downloaded on crates.io
moka-rs/moka
What this package is like to depend on
Last release 14 days ago
09 Aug 2026
Release timing varies
gaps range from 2 weeks to 9 months
Rarely documented
notes for 6 of 61 stable releases
4 versions withdrawn
withdrawn after publishing
6 years old
68 releases · first in 2020
6 releases in the last 12 months
see the full history below
Release timeline
68 releases · Oct 2020 to Aug 2026Releases
latest 60 of 68-
0.12.1609 Aug 2026Release notes
Open source →Version 0.12.16
Fixed
- Fixed a bug where cache eviction could stall permanently when the cache was configured with the non-default LRU eviction policy (
EvictionPolicy::lru()) by a race between insert and remove operations on the same key (#592 by @kim-jhyeon, reported in #590):- This bug was introduced in v0.12.0 and affected
sync::Cache,sync::SegmentedCacheandfuture::Cache. - A race between applying a write recording for an entry and concurrently removing that entry from the internal concurrent hash table could leave an orphaned node at the front of the LRU queue. Once present, no entry was ever evicted again and the cache grew unboundedly past
max_capacity. - The same race also affected the default TinyLFU eviction policy, but with a milder symptom: each occurrence permanently leaked one phantom entry slot, causing
entry_countandweighted_sizeto over-report and the usable capacity to shrink by one entry per occurrence. Fixed by the same change.
- This bug was introduced in v0.12.0 and affected
Changed
- Worked around a ThreadSanitizer false positive (#602):
- Replaced the standalone
fence(Acquire)in the internalMiniArc's drop path with anAcquireload of the reference count, so that downstream projects can now run ThreadSanitizer on code using Moka without hitting this false positive. std::sync::Archas a similar workaround.
- Replaced the standalone
- Raised the minimum version of the
crossbeam-epochcrate fromv0.9.18tov0.9.20to avoid the following advisory (#603):- [RUSTSEC-2026-0204] crossbeam-epoch: invalid pointer dereference in
fmt::PointerforAtomicandShared - Moka is not affected by this advisory because it never formats these pointer types. However, raising the minimum version prevents downstream lockfiles from resolving to an affected
crossbeam-epochversion via Moka.
- [RUSTSEC-2026-0204] crossbeam-epoch: invalid pointer dereference in
Release notes
Open source →Fixed
- Fixed a bug where cache eviction could stall permanently when the cache was
configured with the non-default LRU eviction policy (
EvictionPolicy::lru()) by a race between insert and remove operations on the same key ([#592][gh-pull-0592] by [@kim-jhyeon][gh-kim-jhyeon], reported in [#590][gh-issue-0590]):- This bug was introduced in v0.12.0 and affected
sync::Cache,sync::SegmentedCacheandfuture::Cache. - A race between applying a write recording for an entry and concurrently
removing that entry from the internal concurrent hash table could leave an
orphaned node at the front of the LRU queue. Once present, no entry was ever
evicted again and the cache grew unboundedly past
max_capacity. - The same race also affected the default TinyLFU eviction policy, but with
a milder symptom: each occurrence permanently leaked one phantom entry
slot, causing
entry_countandweighted_sizeto over-report and the usable capacity to shrink by one entry per occurrence. Fixed by the same change.
- This bug was introduced in v0.12.0 and affected
Changed
- Worked around a ThreadSanitizer false positive ([#602][gh-pull-0602]):
- Replaced the standalone
fence(Acquire)in the internalMiniArc's drop path with anAcquireload of the reference count, so that downstream projects can now run ThreadSanitizer on code using Moka without hitting this false positive. std::sync::Archas a similar workaround.
- Replaced the standalone
- Raised the minimum version of the
crossbeam-epochcrate fromv0.9.18tov0.9.20to avoid the following advisory ([#603][gh-pull-0603]):- [RUSTSEC-2026-0204] crossbeam-epoch: invalid pointer dereference in
fmt::PointerforAtomicandShared - Moka is not affected by this advisory because it never formats these
pointer types. However, raising the minimum version prevents downstream
lockfiles from resolving to an affected
crossbeam-epochversion via Moka.
- [RUSTSEC-2026-0204] crossbeam-epoch: invalid pointer dereference in
- Fixed a bug where cache eviction could stall permanently when the cache was configured with the non-default LRU eviction policy (
-
0.12.1522 Mar 2026Release notes
Open source →Version 0.12.15
Fixed
- Fixed a bug where re-inserting an expired entry could cause it to lose its expiration time and remain in the cache indefinitely when using a custom
Expirypolicy with per-entry expiration. (#582 by @jiangzhe, #581 by @atrocities, reported in #575):- This occurred when an entry that had expired but not yet been evicted was re-inserted, and
expire_after_updatereturnedNone. This primarily affected users who only overrideexpire_after_create, since the defaultexpire_after_updatereturnsduration_until_expiry, which isNonefor expired entries. - This bug was introduced by the changes in v0.12.13 (#549 and #564).
- Subtle behavior change:
- Before this fix, re-inserting an expired entry was treated as an update, so
Expiry::expire_after_updatewas called. - After this fix, re-inserting an expired entry is treated as a creation, so
Expiry::expire_after_createis called instead. - This may change the expiration time of re-inserted entries, depending on your
Expirytrait implementation.
- Before this fix, re-inserting an expired entry was treated as an update, so
- This occurred when an entry that had expired but not yet been evicted was re-inserted, and
- Fixed flaky tests
cht::segment::tests::drop_many_valuesanddrop_many_values_concurrentthat were failing on high-core-count machines (#586):- These tests were using a CPU-dependent segment count, causing inconsistent bucket array shrinking behavior of the internal segmented hash map across different machines.
- Changed these tests to use a fixed segment count (4) for consistent results.
Changed
Release notes
Open source →Fixed
- Fixed a bug where re-inserting an expired entry could cause it to lose its
expiration time and remain in the cache indefinitely when using a custom
Expirypolicy with per-entry expiration. ([#582][gh-pull-0582] by [@jiangzhe][gh-jiangzhe], [#581][gh-pull-0581] by [@atrocities][gh-atrocities], reported in [#575][gh-issue-0575]):- This occurred when an entry that had expired but not yet been evicted was
re-inserted, and
expire_after_updatereturnedNone. This primarily affected users who only overrideexpire_after_create, since the defaultexpire_after_updatereturnsduration_until_expiry, which isNonefor expired entries. - This bug was introduced by the changes in v0.12.13 ([#549][gh-pull-0549] and [#564][gh-pull-0564]).
- Subtle behavior change:
- Before this fix, re-inserting an expired entry was treated as an update,
so
Expiry::expire_after_updatewas called. - After this fix, re-inserting an expired entry is treated as a creation,
so
Expiry::expire_after_createis called instead. - This may change the expiration time of re-inserted entries, depending on
your
Expirytrait implementation.
- Before this fix, re-inserting an expired entry was treated as an update,
so
- This occurred when an entry that had expired but not yet been evicted was
re-inserted, and
- Fixed flaky tests
cht::segment::tests::drop_many_valuesanddrop_many_values_concurrentthat were failing on high-core-count machines ([#586][gh-pull-0586]):- These tests were using a CPU-dependent segment count, causing inconsistent bucket array shrinking behavior of the internal segmented hash map across different machines.
- Changed these tests to use a fixed segment count (4) for consistent results.
Changed
- Disabled flaky GC-dependent tests by default using
run_flaky_testscfg ([#584][gh-pull-0584]):- These tests rely on epoch-based garbage collection (
crossbeam-epoch) timing that is not guaranteed, causing intermittent failures. - Fixed [#539][gh-issue-0539] and [#580][gh-issue-0580].
- To run these tests, set
RUSTFLAGS='--cfg run_flaky_tests'.
- These tests rely on epoch-based garbage collection (
- Fixed a bug where re-inserting an expired entry could cause it to lose its expiration time and remain in the cache indefinitely when using a custom
-
0.12.1402 Mar 2026Release notes
Open source →Version 0.12.14
Fixed
- Fixed a race condition in the
and_compute_withmethod in thefuture::Cache. (#574 by @Squadrick):- When multiple calls are made concurrently for the same key, the
fclosure may read a stale value, causing the first update to be lost when it is overwritten by a later one.
- When multiple calls are made concurrently for the same key, the
Changed
- Use
dep:keyword in the crate features. (#577 by @alexanderkjall).
Release notes
Open source →Fixed
- Fixed a race condition in the
and_compute_withmethod in thefuture::Cache. ([#574][gh-pull-0574] by [@Squadrick][gh-Squadrick]):- When multiple calls are made concurrently for the same key, the
fclosure may read a stale value, causing the first update to be lost when it is overwritten by a later one.
- When multiple calls are made concurrently for the same key, the
Changed
- Use
dep:keyword in the crate features. ([#577][gh-pull-0577] by [@alexanderkjall][gh-alexanderkjall]).
- Fixed a race condition in the
-
0.12.1326 Jan 2026Release notes
Open source →Version 0.12.13
Fixed
- Fixed/mitigated use-after-free issues in the hierarchical timer wheels when
ExpiryreturnsNone(Issue #565, reported by @sharksforarms). - Fixed
Expiry::expire_after_updatenot clearing expiration time for expired entries (future::Cache: #549, by @singulared,sync::Cache: #564).
Release notes
Open source →Fixed
- Fixed/mitigated use-after-free issues in the hierarchical timer wheels when
ExpiryreturnsNone(Issue [#565][gh-issue-0565], reported by [@sharksforarms][gh-sharksforarms]).- Fixed a bug that caused freed timer nodes to remain in the timer wheels in some edge cases ([#566][gh-pull-0566] by [@powergee][gh-powergee]).
- The mitigation added to v0.12.12 was enhanced by atomically reading the expiration state to prevent rare race conditions that could cause use-after-free issues ([#570][gh-pull-0570]).
- Fixed
Expiry::expire_after_updatenot clearing expiration time for expired entries (future::Cache: [#549][gh-pull-0549], by [@singulared][gh-singulared],sync::Cache: [#564][gh-pull-0564]).
- Fixed/mitigated use-after-free issues in the hierarchical timer wheels when
-
0.12.1221 Dec 2025Release notes
Open source →Version 0.12.12
Bumped the minimum supported Rust version (MSRV) to 1.71.1, released on August 3, 2023 (#555).
Fixed
- Mitigated use-after-free panic in the hierarchical timer wheels when
ExpiryreturnsNone(#548, by @awarus). - Fixed a subtle undefined behavior in the internal
deque::move_to_backmethod (found by Miri) (#553).
Added
Removed
Release notes
Open source →Bumped the minimum supported Rust version (MSRV) to 1.71.1, released on August 3, 2023 ([#555][gh-pull-0555]).
Fixed
- Mitigated use-after-free issues in the hierarchical timer wheels when
ExpiryreturnsNone([#548][gh-pull-0548], by [@awarus][gh-awarus]). - Fixed a subtle undefined behavior in the internal
deque::move_to_backmethod (found by Miri) ([#553][gh-pull-0553]).
Added
impl Expiryfor some types ([#519][gh-pull-0519], by [@koushiro][gh-koushiro]).
Removed
- Removed several unneeded files from the published package ([#541][gh-pull-0541], by [@weiznich][gh-weiznich]).
- Removed the
once_cellcrate from the dependencies ([#520][gh-pull-0520], by [@Expyron][gh-Expyron]). - Removed the
rustc_versioncrate from the dev-dependencies ([#554][gh-pull-0554]).
- Mitigated use-after-free panic in the hierarchical timer wheels when
-
0.12.1123 Sep 2025Release notes
Open source →Breaking Changes
- After releasing v0.12.11, we found that supporting
Equivalenttrait was an unintended breaking change.- If you get a compilation error something like following, please update your
code to reborrow the key like
&*key.-
error[E0277]: the trait bound `T: Borrow<Arc<T>>` is not satisfied ... = note: required for `Arc<T>` to implement `Equivalent<T>`
-
- See this PR comment for more details.
- If you get a compilation error something like following, please update your
code to reborrow the key like
Added
- Support
Equivalenttrait for the key typeKof the caches. (#492) - Added the
jittered_expiry_policyexample (#489).
Changed
- Adjusted license expression: some code is Apache-2.0 only (#529, by
@musicinmybrain).
- The license expression in
Cargo.tomlwas changed fromMIT OR Apache-2.0to(MIT OR Apache-2.0) AND Apache-2.0. - See the license section of the README for details.
- The license expression in
- Upgrading a crate in the dependencies:
- Raised the minimum version of
crossbeam-channelcrate fromv0.5.5tov0.5.15to avoid the following issue (#514, by karankurbur).- RUSTSEC-2025-0024 crossbeam-channel: double free on Drop
- Raised the minimum version of
- Moving a crate from the dependencies to the dev-dependencies:
- Switched
loomcrate to a dev-dependency (#509, by thomaseizinger).
- Switched
- Updating a crate in the dev-dependencies:
- Upgraded
reqwestcrate in the dev-dependencies fromv0.11tov0.12(#531, by musicinmybrain).
- Upgraded
Removed
- Removing a crate from the dependencies:
- Removed
thiserrorcrate by manually implementingstd::error::Errorformoka::PredicateError(#512, by @brownjohnf).
- Removed
- Removing crates from the dev-dependencies:
- Removed unmaintained
pastecrate from the dev-dependencies (#504).- RUSTSEC-2024-0436 paste - no longer maintained
- Removed discontinued
async-stdcrate from the dev-dependencies (#534).- RUSTSEC-2025-0052 async-std has been discontinued
- Removed unmaintained
- Removed clippy ignore
non_send_fields_in_send_tythat no longer applies (#505, by @qti3e).
Fixed
- Remove redundant word in source code comment (#532, by @quantpoet).
Version 0.12.10
Changed
- Disabled the
quantafeature by default. (#482) - Replaced most uses of
quanta::Instantwithstd::time::Instantto increase the accuracy of time measurements (#481):- When
quantafeature is enabled,quanta::Instantis used for some performance critical parts in the cache, andstd::time::Instantis used for the rest of the parts. - However, as of this version, enabling the
quantafeature will not make any noticeable difference in the performance. - When
quantafeature is disabled (default),std::time::Instantis used for all time measurements.
- When
- Switched to
AtomicU64of theportable-atomiccrate, which provides fallback implementations for platforms wherestdAtomicU64is not available (#480):moka'satomic64feature no longer has any effect on the build asAtomicU64is now always available on all platforms. But we keep theatomic64feature inCargo.tomlfor backward compatibility.
Version 0.12.9
Bumped the minimum supported Rust version (MSRV) to 1.70 (June 1, 2023) (#474).
Fixed
- Prevent an occasional panic in an internal
to_std_instantmethod when per-entry expiration policy is used. (#472) - Documentation: Removed leftover mentions of background threads.
(#464)
- Also added the implementation details chapter to the crate top-level documentation to explain some internal behavior of the cache.
Added
- Added
and_try_compute_if_nobody_elsemethod tofuture::Cache'sentryAPI. (#460, by @xuehaonan27)
Removed
- Removed
triomphecrate from the dependency by adding our own internalArctype. (#456)- Our
Arcwill be more memory efficient thanstd::sync::Arcortriomphe::Arcon 64-bit platforms as it uses a singleAtomicU32counter.
- Our
- Removed needless traits along with
async-traitusage. (#445, by @Swatinem)
Changed
- Enable
atomic64feature only when target supportsAtomicU64. (#466, by @zonyitoo) - Made
once_celldependency optional (#444). - Stopped creating references unnecessarily to compare pointers by-address. (#452, by @JoJoDeveloping)
Version 0.12.8
Fixed
- Avoid to use recent versions (
v0.1.12or newer) oftriomphecrate to keep our MSRV (Minimum Supported Rust Version) at Rust 1.65 (#426, by @eaufavor).[email protected]requires Rust 1.76 or newer, so it will not compile with our MSRV.
- docs: Fix per-entry expiration policy documentation (#421, by @arcstur).
Version 0.12.7
Changed
- Ensure a single call to
run_pending_tasksto evict as many entries as possible from the cache (#417).
Version 0.12.6
Fixed
- Fixed a bug in
future::Cachethat pendingrun_pending_taskscalls may cause infinite busy loop in an internalschedule_write_opmethod (#412):- This bug was introduced in
v0.12.0when the background threads were removed fromfuture::Cache. - This bug can occur when
run_pending_taskmethod is called by user code while cache is receiving a very high number of concurrent cache write operations. (e.g.insert,get_with,invalidateetc.) - When it occurs, the
schedule_write_opmethod will be spinning in a busy loop forever, causing high CPU usage and all other async tasks to be starved.
- This bug was introduced in
Changed
- Upgraded
async-lockcrate used byfuture::Cachefromv2.4to the latestv3.3.
Version 0.12.5
Added
- Added support for a plain LRU (Least Recently Used) eviction policy
(#390):
- The LRU policy is enabled by calling the
eviction_policymethod of the cache builder with a policy obtained byEvictionPolicy::lrufunction. - The default eviction policy remains the TinyLFU (Tiny, Least Frequently Used) as it maintains better hit rate than LRU for most use cases. TinyLFU combines LRU eviction policy and popularity-based admission policy. A probabilistic data structure is used to estimate historical popularity of both hit and missed keys. (not only the keys currently in the cache.)
- However, some use cases may prefer LRU policy over TinyLFU. An example is recency biased workload such as streaming data processing. LRU policy can be used for them to achieve better hit rate.
- Note that we are planning to add an adaptive eviction/admission policy called Window-TinyLFU in the future. It will adjust the balance between recency and frequency based on the current workload.
- The LRU policy is enabled by calling the
Version 0.12.4
Fixed
- Ensure
crossbeam-epochto run GC when dropping a cache (#384):crossbeam-epochcrate provides an epoch-based memory reclamation scheme for concurrent data structures. It is used by Moka cache to safely drop cached entries while they are still being accessed by other threads.crossbeam-epochdoes its best to reclaim memory (drop the entries evicted from the cache) when the epoch is advanced. However, it does not guarantee that memory will be reclaimed immediately after the epoch is advanced. This means that entries can remain in the memory for a while after the cache is dropped.- This fix ensures that, when a cache is dropped, the epoch is advanced and
crossbeam-epoch's thread local buffers are flushed, helping to reclaim memory immediately. - Note that there are still chances that some entries remain in the memory for a
while after a cache is dropped. We are looking for alternatives to
crossbeam-epochto improve this situation (e.g. #385).
Added
- Added an example for reinserting expired entries to the cache. (#382)
Version 0.12.3
Added
- Added the upsert and compute methods for modifying a cached entry
(#370):
- Now the
entryandentry_by_refAPIs have the following methods:and_upsert_withmethod to insert or update the entry.and_compute_withmethod to insert, update, remove or do nothing on the entry.and_try_compute_withmethod, which is similar to above but returnsResult.
- Now the
Fixed
- Raised the version requirement of the
quantafrom>=0.11.0, <0.12.0to>=0.12.2, <0.13.0to avoid under-measuring the elapsed time on Apple silicon Macs (#376).- Due to this under-measurement, cached entries on macOS arm64 can expire sightly later than expected.
Version 0.12.2
Fixed
- Prevent timing issues in writes that cause inconsistencies between the cache's
internal data structures (#348):
- One way to trigger the issue is that insert the same key twice quickly, once
when the cache is full and a second time when there is a room in the cache.
- When it occurs, the cache will not return the value inserted in the second
call (which is wrong), and the
entry_countmethod will keep returning a non zero value after calling theinvalidate_allmethod (which is also wrong).
- When it occurs, the cache will not return the value inserted in the second
call (which is wrong), and the
- One way to trigger the issue is that insert the same key twice quickly, once
when the cache is full and a second time when there is a room in the cache.
- Now the last access time of a cached entry is updated immediately after the entry
is read (#363):
- When the time-to-idle of a cache is set, the last access time of a cached entry is used to determine if the entry has been expired.
- Before this fix, the access time was updated (to the time when it was read) when pending tasks were processed. This delay caused issue that some entries become temporarily unavailable for reads even though they have been accessed recently. And then they will become available again after the pending tasks are processed.
- Now the last access time is updated immediately after the entry is read. The entry will remain valid until the time-to-idle has elapsed.
Note that both of #348 and #363 were already present in
v0.11.xand older versions. However they were less likely to occur because they had background threads to periodically process pending tasks. So there were much shorter time windows for these issues to occur.Changed
- Updated the Rust edition from 2018 to 2021. (#339, by
@nyurik)
- The MSRV remains at Rust 1.65.
- Changed to use inline format arguments throughout the code, including examples. (#340, by @nyurik)
Added
- Added an example for cascading drop triggered by eviction (#350, by @peter-scholtens)
Version 0.12.1
Fixed
- Fixed memory leak in
future::Cachethat occurred whenget_with(),entry().or_insert_with(), and similar methods were used (#329).- This bug was introduced in
v0.12.0. Versions prior tov0.12.0do not have this bug.
- This bug was introduced in
Changed
Version 0.12.0
Note
v0.12.0has major breaking changes on the API and internal behavior.-
synccaches are no longer enabled by default: Please use a crate featuresyncto enable it. -
No more background threads: All cache types
future::Cache,sync::Cache, andsync::SegmentedCacheno longer spawn background threads.- The
scheduled-thread-poolcrate was removed from the dependency. - Because of this change, many private methods and some public methods under the
futuremodule were converted toasyncmethods. You may need to add.awaitto your code for those methods.
- The
-
Immediate notification delivery: The
notification::DeliveryModeenum for the eviction listener was removed. Now all cache types behave as if theImmediatedelivery mode is specified.
Please read the MIGRATION-GUIDE.md for more details.
Changed
- Removed the thread pool from
futurecache (#294) andsynccaches (#316). - Improved async cancellation safety of
future::Cache. (#309)
Fixed
- Fixed a bug that an internal
do_insert_with_hashmethod gets the currentInstanttoo early when eviction listener is enabled. (#322)
Version 0.11.3
Fixed
- Fixed a bug in
sync::Cacheandsync::SegmentedCachewhere memory usage kept increasing when the eviction listener was set with theImmediatedelivery mode. (#295)
Version 0.11.2
Bumped the minimum supported Rust version (MSRV) to 1.65 (Nov 3, 2022). (#275)
Removed
- Removed
num_cpuscrate from the dependency. (#277)
Changed
- Refactored internal methods of the concurrent hash table to reduce compile times. (#265, by @Swatinem)
Version 0.11.1
Fixed
- Fixed occasional panic in internal
FrequencySketchin debug build. (#272)
Added
- Added some example programs to the
examplesdirectory. (#268, by @peter-scholtens)
Version 0.11.0
Added
- Added support for per-entry expiration (#248):
- In addition to the existing TTL and TTI (time-to-idle) expiration times that
apply to all entries in the cache, the
syncandfuturecaches can now allow different expiration times for individual entries.
- In addition to the existing TTL and TTI (time-to-idle) expiration times that
apply to all entries in the cache, the
- Added the
removemethod to thesyncandfuturecaches (#255):- Like the
invalidatemethod, this method discards any cached value for the key, but returns a clone of the value.
- Like the
Fixed
- Fixed the caches mutating a deque node through a
NonNullpointer derived from a shared reference. (#259)
Removed
- Removed
unsynccache that was marked as deprecated in v0.10.0.
Version 0.10.2
Bumped the minimum supported Rust version (MSRV) to 1.60 (Apr 7, 2022). (#252)
Changed
- Upgraded
quantacrate to v0.11.0. (#251)- This resolved "RUSTSEC-2020-0168:
machis unmaintained" (#243) by replacingmachwithmach2. quantav0.11.0's MSRV is 1.60, so we also bumped the MSRV of Moka to 1.60.
- This resolved "RUSTSEC-2020-0168:
Version 0.10.1
Fixed
- Fixed a bug that
futurecache'sblocking().invalidate(key)method does not trigger the eviction listener. (#242)
Changed
- Now
syncandfuturecaches will not cache anything when the max capacity is set to zero (#230):- Previously, they would cache some entries for short time (< 0.5 secs) even though the max capacity is zero.
Version 0.10.0
Breaking Changes
- The following caches have been moved to a separate crate called
Mini-Moka:
moka::unsync::Cache→mini_moka::unsync::Cachemoka::dash::Cache→mini_moka::sync::Cache
- The following methods have been removed from
syncandfuturecaches (#199). They were deprecated in v0.8.0:get_or_insert_with(Useget_withinstead)get_or_try_insert_with(Usetry_get_withinstead)
- The following methods of
syncandfuturecaches have been marked as deprecated (#193):get_with_if(UseentryAPI'sor_insert_with_ifinstead)
Added
- Add
entryandentry_by_refAPIs tosyncandfuturecaches (#193):- They allow users to perform more complex operations on a cache entry. At this
point, the following operations (methods) are provided:
or_defaultor_insertor_insert_withor_insert_with_ifor_optionally_insert_withor_try_insert_with
- The above methods return
Entrytype, which providesis_freshmethod to check if the value was freshly computed or already existed in the cache.
- They allow users to perform more complex operations on a cache entry. At this
point, the following operations (methods) are provided:
Version 0.9.7
Fixed
- Fix an issue that
get_withmethod offuturecache inflates future size by ~7x, sometimes causing stack overflow (#212):- This was caused by a known
rustcoptimization issue on async functions (rust-lang/rust#62958). - Added a workaround to our cache and now it will only inflate the size by ~2.5x.
- This was caused by a known
- Fix a bug that setting the number of segments of
synccache will disable notifications. (#207)
Added
- Add examples for
build_with_hashermethod of cache builders. (#216)
Version 0.9.6
Fixed
- Prevent race condition in
get_withfamily methods to avoid evaluatinginitclosure or future multiple times in concurrent calls. (#195)
Version 0.9.5
Added
- Add
optionally_get_withmethod tosyncandfuturecaches (#187, by @LMJW):- It is similar to
try_get_withbut takes an init closure/future returning anOption<V>instead ofResult<V, E>.
- It is similar to
- Add
by_refversion of API forget_with,optionally_get_with, andtry_get_withofsyncandfuturecaches (#190, by @LMJW):- They are similar to the non-
by_refversions but take a reference of the key instead of an owned key. If the key does not exist in the cache, the key will be cloned to create new entry in the cache.
- They are similar to the non-
Changed
Fixed
Version 0.9.4
Fixed
- Fix memory leak after dropping a
syncorfuturecache (#177):- This leaked the value part of cache entries.
Added
- Add an experimental
jsfeature to makeunsyncandsynccaches to compile forwasm32-unknown-unknowntarget (#173, by @aspect):- Note that we have not tested if these caches work correctly in wasm32 environment.
Version 0.9.3
Added
- Add an option to the cache builder of the following caches not to start and use the
global thread pools for housekeeping tasks (#165):
sync::Cachesync::SegmentedCache
Fixed
- Ensure that the following caches will drop the value of evicted entries immediately
after eviction (#169):
sync::Cachesync::SegmentedCachefuture::Cache
Version 0.9.2
Fixed
- Fix segmentation faults in
syncandfuturecaches under heavy loads on many-core machine (#34):- NOTE: Although this issue was found in our testing environment ten months ago (v0.5.1), no user reported that they had the same issue.
- NOTE: In v0.8.4, we added a mitigation to reduce the chance of the segfaults occurring.
Changed
- Upgrade crossbeam-epoch from v0.8.2 to v0.9.9 (#157):
- This will make GitHub Dependabot to stop alerting about a security advisory CVE-2022-23639 for crossbeam-utils versions < 0.8.7.
- Moka v0.9.1 or older was not vulnerable to the CVE:
- Although the older crossbeam-epoch v0.8.2 depends on an affected version of crossbeam-utils, epoch v0.8.2 does not use the affected functions of utils. (#162)
Version 0.9.1
Fixed
- Relax a too restrictive requirement
Arc<K>: Borrow<Q>for the key&Qof thecontains_key,getandinvalidatemethods in the following caches (withKas the key type) (#167). The requirement is nowK: Borrow<Q>so these methods will accept&[u8]for the key&Qwhen the stored keyKisVec<u8>.sync::Cachesync::SegmentedCachefuture::Cache
Version 0.9.0
Added
- Add support for eviction listener to the following caches (#145).
Eviction listener is a callback function that will be called when an entry is
removed from the cache:
sync::Cachesync::SegmentedCachefuture::Cache
- Add a crate feature
syncfor enabling and disablingsynccaches. (#141 by @Milo123459, and #143)- This feature is enabled by default.
- When using experimental
dashcache, opting out ofsyncwill reduce the number of dependencies.
- Add a crate feature
loggingto enable optional log crate dependency. (#159)- Currently log will be emitted only when an eviction listener has panicked.
Version 0.8.6
Fixed
- Fix a bug caused
invalidate_allandinvalidate_entries_ifof the following caches will not invalidate entries inserted just before calling them (#155):sync::Cachesync::SegmentedCachefuture::Cache- Experimental
dash::Cache
Version 0.8.5
Added
- Add basic stats (
entry_countandweighted_size) methods to all caches. (#137) - Add
Debugimpl to the following caches (#138):sync::Cachesync::SegmentedCachefuture::Cacheunsync::Cache
Fixed
- Remove unnecessary
K: Clonebound from the following caches when they areClone(#133):sync::Cachefuture::Cache- Experimental
dash::Cache
Version 0.8.4
Fixed
- Fix the following issue by upgrading Quanta crate to v0.10.0 (#126):
- Quanta v0.9.3 or older may not work correctly on some x86_64 machines where the Time Stamp Counter (TSC) is not synched across the processor cores. (#119)
- For more details about the issue, see the relevant section of the README.
Added
- Add
get_with_ifmethod to the following caches (#123):sync::Cachesync::SegmentedCachefuture::Cache
Changed
The followings are internal changes to improve memory safety in unsafe Rust usages in Moka:
- Remove pointer-to-integer transmute by converting
UnsafeWeakPointerfromusizeto*mut T. (#127, by saethlin) - Increase the num segments of the waiters hash table from 16 to 64
(#129) to reduce the chance of the following issue occurring:
- Segfaults under heavy workloads on a many-core machine. (#34)
Version 0.8.3
Changed
- Make Quanta crate optional (but enabled by default)
(#121)
- Quanta v0.9.3 or older may not work correctly on some x86_64 machines where the Time Stamp Counter (TSC) is not synched across the processor cores. (#119)
- This issue was fixed by Quanta v0.10.0. You can prevent the issue by upgrading Moka to v0.8.4 or newer.
- For more details about the issue, see the relevant section of the README.
Version 0.8.2
Added
- Add iterator to the following caches: (#114)
sync::Cachesync::SegmentedCachefuture::Cacheunsync::Cache
- Implement
IntoIteratorto the all caches (including experimentaldash::Cache) (#114)
Fixed
- Fix the
dash::Cacheiterator not to return expired entries. (#116) - Prevent "index out of bounds" error when
sync::SegmentedCachewas created with a non-power-of-two segments. (#117)
Version 0.8.1
Added
- Add
contains_keymethod to check if a key is present without resetting the idle timer or updating the historic popularity estimator. (#107)
Version 0.8.0
As a part of stabilizing the cache API, the following cache methods have been renamed:
get_or_insert_with(K, F)→get_with(K, F)get_or_try_insert_with(K, F)→try_get_with(K, F)
Old methods are still available but marked as deprecated. They will be removed in a future version.
Also
policymethod was added to all caches andblockingmethod was added tofuture::Cache. They return aPolicystruct orBlockingOpstruct respectively. Some uncommon cache methods were moved to these structs, and old methods were removed without deprecating.Please see #105 for the complete list of the affected methods.
Changed
- API stabilization. (Smaller core cache API, shorter names for common methods) (#105)
- Performance related:
- Update the minimum versions of dependencies:
- crossbeam-channel to v0.5.4. (#100)
- scheduled-thread-pool to v0.2.5. (#103, by @Milo123459)
- (dev-dependency) skeptic to v0.13.5. (#104)
Added
Experimental Additions
- Add a synchronous cache
moka::dash::Cache, which usesdashmap::DashMapas the internal storage. (#99) - Add iterator to
moka::dash::Cache. (#101)
Please note that the above additions are highly experimental and their APIs will be frequently changed in next few releases.
Version 0.7.2
The minimum supported Rust version (MSRV) is now 1.51.0 (Mar 25, 2021).
Fixed
- Addressed a memory utilization issue that will get worse when keys have hight
cardinality (#72):
- Reduce memory overhead in the internal concurrent hash table (cht). (#79)
- Fix a bug that can create oversized frequency sketch when weigher is set. (#75)
- Change
EntryInfofromenumtostructto reduce memory utilization. (#76) - Replace some
std::sync::Arcusages withtriomphe::Arcto reduce memory utilization. (#80) - Embed
CacheRegionvalue into a 2-bit tag space ofTagNonNullpointer. (#84)
- Fix a bug that will use wrong (oversized) initial capacity for the internal cht. (#83)
Added
- Add
unstable-debug-countersfeature for testing purpose. (#82)
Changed
- Import (include) cht source files for better integration. (#77, #86)
- Improve the CI coverage for Clippy lints and fix some Clippy warnings in unit tests. (#73, by @06chaynes)
Version 0.7.1
- Important Fix: A memory leak issue (#65 below) was found in all previous versions (since v0.1.0) and fixed in this version. All users are encouraged to upgrade to this or newer version.
Fixed
- Fix a memory leak that will happen when evicting/expiring an entry or manually invalidating an entry. (#65)
Changed
- Update the minimum depending version of crossbeam-channel from v0.5.0 to v0.5.2. (#67)
Version 0.7.0
- Breaking change: The type of the
max_capacityhas been changed fromusizetou64. This was necessary to have the weight-based cache management consistent across different CPU architectures.
Added
- Add support for weight-based (size aware) cache management. (#24)
- Add support for unbound cache. (#24)
Version 0.6.3
Fixed
- Fix a bug in
get_or_insert_withandget_or_try_insert_withmethods offuture::Cache, which caused a panic if previously inserting task aborted. (#59)
Version 0.6.2
Removed
- Remove
Sendand'staticbounds fromget_or_insert_withandget_or_try_insert_withmethods offuture::Cache. (#53, by @tinou98)
Fixed
- Protect overflow when computing expiration. (#56, by @barkanido)
Version 0.6.1
Changed
Version 0.6.0
Fixed
- Fix a bug in
get_or_insert_withandget_or_try_insert_withmethods offuture::Cacheandsync::Cache; a panic in theinitfuture/closure causes subsequent calls on the same key to get "unreachable code" panics. (#43)
Changed
- Change
get_or_try_insert_withto return a concrete error type rather than a trait object. (#23, #37)
Version 0.5.4
Changed
- Restore quanta dependency on some 32-bit platforms such as
armv5te-unknown-linux-musleabiormips-unknown-linux-musl. (#42, by @messense)
Version 0.5.3
Added
- Add support for some 32-bit platforms where
std::sync::atomic::AtomicU64is not provided. (e.g.armv5te-unknown-linux-musleabiormips-unknown-linux-musl) (#38)- On these platforms, you will need to disable the default features of Moka. See the relevant section of the README.
Version 0.5.2
Fixed
- Fix a bug in
get_or_insert_withandget_or_try_insert_withmethods offuture::Cacheby adding missing boundsSendand'staticto theinitfuture. Without this fix, these methods will accept non-Sendor non-'staticfuture and may cause undefined behavior. (#31) - Fix
usizeoverflow on big cache capacity. (#28)
Added
- Add examples for
get_or_insert_withandget_or_try_insert_withmethods to the docs. (#30)
Changed
- Downgrade crossbeam-epoch used in moka-cht from v0.9.x to v0.8.x as a possible workaround for segmentation faults on many-core CPU machines. (#33)
Version 0.5.1
Changed
- Replace a dependency cht v0.4 with moka-cht v0.5. (#22)
Version 0.5.0
Added
- Add
get_or_insert_withandget_or_try_insert_withmethods tosyncandfuturecaches. (#20)
Version 0.4.0
Fixed
- Breaking change: Now
sync::{Cache, SegmentedCache}andfuture::CacherequireSend,Syncand'staticfor the generic parametersK(key),V(value) andS(hasher state). This is necessary to prevent potential undefined behaviors in applications using single-threaded async runtime such as Actix-rt. (#19)
Added
- Add
invalidate_entries_ifmethod tosync,futureandunsynccaches. (#12)
Version 0.3.1
Changed
- Stop skeptic from having to be compiled by all downstream users. (#16, by @paolobarbolini)
Version 0.3.0
Added
- Add an unsync cache (
moka::unsync::Cache) and its builder for single-thread applications. (#9) - Add
invalidate_allmethod tosync,futureandunsynccaches. (#11)
Fixed
- Fix problems including segfault caused by race conditions between the sync/eviction thread and client writes. (Addressed as a part of #11).
Version 0.2.0
Added
- Add an asynchronous, futures aware cache (
moka::future::Cache) and its builder. (#7)
Version 0.1.0
Added
- Add thread-safe, highly concurrent in-memory cache implementations
(
moka::sync::{Cache, SegmentedCache}) with the following features:- Bounded by the maximum number of elements.
- Maintains good hit rate by using entry replacement algorithms inspired by
Caffeine:
- Admission to a cache is controlled by the Least Frequently Used (LFU) policy.
- Eviction from a cache is controlled by the Least Recently Used (LRU) policy.
- Expiration policies:
- Time to live
- Time to idle
<!-- Links -->
- After releasing v0.12.11, we found that supporting
-
0.12.1006 Jan 2025Nothing published for this version
-
0.12.902 Jan 2025Nothing published for this version
-
0.12.807 Jul 2024Nothing published for this version
-
0.12.718 Apr 2024Nothing published for this version
-
0.12.612 Apr 2024Nothing published for this version
-
0.12.529 Jan 2024Nothing published for this version
-
0.12.422 Jan 2024Nothing published for this version
-
0.12.309 Jan 2024Nothing published for this version
-
0.12.228 Dec 2023Nothing published for this version
-
0.12.103 Oct 2023Nothing published for this version
-
0.12.018 Sep 2023Nothing published for this version
-
0.12.0-beta.310 Sep 2023 pre-releaseNothing published for this version
-
0.12.0-beta.204 Sep 2023 pre-releaseNothing published for this version
-
0.12.0-beta.127 Aug 2023 pre-releaseNothing published for this version
-
0.11.306 Aug 2023Nothing published for this version
-
0.11.208 Jun 2023Nothing published for this version
-
0.11.129 May 2023Nothing published for this version
-
0.11.001 May 2023Nothing published for this version
-
0.10.406 Aug 2023Nothing published for this version
-
0.10.305 Jul 2023Nothing published for this version
-
0.10.204 Apr 2023Nothing published for this version
-
0.10.128 Mar 2023Nothing published for this version
-
0.10.010 Feb 2023Nothing published for this version
-
0.9.906 Aug 2023Nothing published for this version
-
0.9.804 Jul 2023Nothing published for this version
-
0.9.706 Feb 2023Nothing published for this version
-
0.9.606 Nov 2022Nothing published for this version
-
0.9.501 Nov 2022Nothing published for this version
-
0.9.405 Sep 2022Nothing published for this version
-
0.9.304 Aug 2022Nothing published for this version
-
0.9.219 Jul 2022Nothing published for this version
-
0.9.117 Jul 2022Nothing published for this version
-
0.9.005 Jul 2022Nothing published for this version
-
0.8.627 Jun 2022Nothing published for this version
-
0.8.528 May 2022Nothing published for this version
-
0.8.420 May 2022Nothing published for this version
-
0.8.315 May 2022Nothing published for this version
-
0.8.212 Apr 2022Nothing published for this version
-
0.8.104 Apr 2022Nothing published for this version
-
0.8.023 Mar 2022Nothing published for this version
-
0.7.206 Feb 2022Nothing published for this version
-
0.7.111 Jan 2022Nothing published for this version
-
0.7.004 Jan 2022Nothing published for this version
-
0.6.412 Jan 2022Nothing published for this version
-
0.6.328 Dec 2021Nothing published for this version
-
0.6.219 Dec 2021Nothing published for this version
-
0.6.122 Sep 2021Nothing published for this version
-
0.6.020 Sep 2021Nothing published for this version
-
0.5.418 Sep 2021Nothing published for this version
-
0.5.310 Sep 2021Nothing published for this version
-
0.5.206 Sep 2021Nothing published for this version
-
0.5.103 Aug 2021Nothing published for this version
-
0.5.008 Jul 2021Nothing published for this version
-
0.4.020 Jun 2021Nothing published for this version