Is there a reason the weigher only supports u32, while max capacity is u64? #409
-
Basically the title. I'm trying to use moka with size-based-evictions, as detailed in https://docs.rs/moka/latest/moka/future/struct.Cache.html#example-size-based-eviction, but the limitation on u32 entry weights makes this impractical for some use-cases. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Thank you for using moka. It uses Entry weights are relative values so you can scale your original value to fit in the 2^32 range, and scale the max capacity as well. |
Beta Was this translation helpful? Give feedback.
Thank you for using moka.
It uses
u32
for entry weight rather thanu64
to reduce memory overhead. A cache instance must hold the weight values of all entries so a small data type (u32
4 bytes) is preferable than a large data type (u64
8 bytes). It usesu64
for the max capacity andweighted_size
(the sum of the weight values of all entries) to avoid arithmetic overflow (e.g.u32::MAX + 1u32
) . The memory overhead are small for them because a cache instance only needs to hold oneu64
for each.Entry weights are relative values so you can scale your original value to fit in the 2^32 range, and scale the max capacity as well.