What's the recommended way to persist the cache between application runs? #828
-
So, I do get that Caffeine is an in-memory cache, and I'm not asking for an on-disk cache or a fallback to disk if too much memory is consumed. But I do wonder whether there's a recommended way / default implementation to persist the cache between applications runs. Basically, serialize the cache on application exit, and deserialize it again on the next start of the application. Is there something like this already built into Caffeine? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
I believe usually what is needed to implement this is ordered access, e.g. to capture the X% hottest entries. If you want to capture everything without order then the Java serialization is supported but only captures the configuration and not the data. That is to be usable in distributed compute logic, e.g. Spark functions, where the data should be marshalled more efficiently. |
Beta Was this translation helpful? Give feedback.
I believe usually what is needed to implement this is ordered access, e.g. to capture the X% hottest entries. If you want to capture everything without order then the
asMap()
view is ideal, but for a fast restart that might be too much data. Thecache.policy()
apis expose methods like<T> T hottest(Function<Stream<CacheEntry<K, V>>, T> mappingFunction)
, with convenience versions for count or weight. These require locking so the functions should be fast snapshots with the serialization performed afterwards.Java serialization is supported but only captures the configuration and not the data. That is to be usable in distributed compute logic, e.g. Spark functions, where the data should be m…