Closed lorepozo closed 8 months ago
Hi. Thank you for the idea! Unfortunately, there is another feature request to expose the metadata of cached entries; many of the values in the metadata are std::time::Instant
.
I am not sure what to do (yet), but maybe we will add a crate feature, and when it is enabled, use quanta::Instant
in the API where std::time::Instant
is used?
By the way, if you do not need Expiry
, you could use v0.10.4 until we found a solution for the std::time::Instant
issue. (v0.10.x does not have Expiry
) We are still back-porting important bug fixes to v0.9.x, v0.10.x and v0.11.x.
A while ago, I was able to build and run very basic stuff for wasm32-unknown-unknown
target using v0.9.4: https://github.com/moka-rs/moka/pull/173#issuecomment-1229589804. However we made no progress after that.
I do not have enough knowledge and experience in wasm to make a good decision on this, but I think moka would not be a good choice for a product that runs on wasm32-unknown-unknown
target.
moka has the following downsides when used in a wasm target:
wasm32-unknown-unknown
target today.Arc
to share data between threads. An Arc
itself only adds a small memory overhead. However, the cache can use a large number of Arc
s when having many cached entries, so the overhead could be significant.Have you checked other crates that provide smaller feature sets?
You may want to check the following crates:
mini_moka::unsync::Cache
)and maybe you want to tell us what features are missing from mini-moka for your project.
Closing as there are no activities. Feel free to reopen if needed.
When creating a new moka::sync::Cache on wasm32-unknown-unknown, a panic results:
time is not implemented on this platform
. This is becausestd::time::Instant::now()
is being called.moka already has a
quanta
feature which uses its version ofInstant
that supports wasm32-unknown-unknown. But despite that feature being enabled,std::time::Instant
is also used.It appears necessary because of the
pub trait Expiry
which provides configurable behavior based onstd::time::Instant
:current_time
andlast_modified_at
. That means resolving this issue — enabling moka::sync::Cache on wasm — requires a breaking change to the API.The Expiry trait could be changed as follows:
current_time
is generally unnecessary as the implementation can do it if desired, andlast_modified_at
may instead be something likeduration_since_modified
. E.g.: