Any Java caches that can limit memory usage of in-memory cache, not just instance count?

后端 未结 8 2488
后悔当初
后悔当初 2021-02-14 00:08

I am looking for a simple in-memory (and in-process) cache for short-term caching of query data (but short-term meaning beyond request/response, i.e. session boundary). EhCache

8条回答
  •  无人共我
    2021-02-14 00:46

    It's not just hard to measure - it's hard to define.

    Suppose two cache entries refer to the same string - do they both count the size of that string, despite the fact that removing either of them from the cache wouldn't make the string eligible for garbage collection? Do neither of them count the size, despite the fact that if both of them are removed from the cache the string may then be eligible for collection? What about if another object not in the cache has a reference to that string?

    If you can accurately describe the size you're interested in it may be possible to ascertain it programmatically - but I suspect you'll find it's hard even to decide exactly what you want.

提交回复
热议问题