I’m trying to create a simple session cache that allows me to set a maximum size on the whole cache. The cache is not a computing cache, so I think Guava’s CacheBuilder with a LoadingCache is not appropriate. I want to be able perform the following operations:
get(key) data from the cache that was previously stashed during a stashing operation
put(key,value) into the cache during the stashing operation
I tried using MapMaker but the maximum size method seems to be antiquated. Does anyone know what options I have? I can always resort to just using a simple Map and rolling my own policy I suppose?
So use the
CacheBuilderwithout it. It works exactly the same, except that you call plainbuild()instead ifbuild(CacheLoader). Everything stays the same, except for you get a “normal” cache instead of a loading one. That’s all.Caching via
MapMaperwill go away one day, forget it.The example is very trivial, just create
and then try this: