can cache2k evict the entries (or overflow to disk) based on memory size (in bytes) based limit?
In a few days I will release version 1.4 which includes support for a Weigher
. With that you can provide a method that gets called whenever an entry is created or updated, which returns a weight of the entry, for example reflecting its approximate size on the heap. This includes the possibility to wire in libraries that estimate the memory size of an entry, which would provide what you asked for.
Every library that estimates the size needs to navigate through the object references. This is costly and might fail in case some global objects are referenced. For example referenced String object might be interned.
In some cases a weigher is very easy to implement. For example if images with byte arrays are cached, the weigher can just return the array size.
In case your cache entries are similar in size I recommend not using the weigher.
Even a simple weigher implementation, does incur overhead. With a weigher present an entry update leads to an update of a global data (the total weight in the cache) and needs additional locking and synchronization.
can cache2k overflow to disk?
That was present in versions prior to 1.0 but removed in a cleanup to focus on a pure heap based cache. However, the overall design of the API and internal structure still keeps that in mind, so the feature could be added again.
At some point that might happen, but not soon.