> Could you elaborate on the performance concern a bit, not sure if I completely got your point.
My point was just to take the simplest, easiest to maintain solution
that fits your needs. I try not to advocate CLHM when alternative
solutions are acceptable and require less integration code.
In the reasoning I had, my point was that the performance penalty is
the DB access (uniform cost) due to a cache miss. Any LRU cache (CLHM,
Ehcache, LinkedHashMap) should perform well enough for the in-memory
operations. This is because even synchronization of a naive
LinkedHashMap might cost 100s of nanoseconds, whereas the cache miss
to the database would be in the milliseconds range. So in common
cases, a simple approach is acceptable because the value is in the LRU
algorithm and not the concurrency characteristics. In cases where the
synchronization penalty is noticeable, then CLHM would provide a
substantial speed-up.
In the cases where the cache's in-memory performance is critical the
difference between LinkedHashMap and CLHM should be night and day. The
difference between MapMaker and CLHM should be less so, with a small
win for CLHM due to some better design choices. We may eventually
integrate those improvements into MapMaker, but due to some complexity
issues due to design differences we decided to hold off for now. Those
aspects may be niche enough that the current #maximumSize()
implementation will stay as is, since so far everyone internally at
Google has been quite happy with its concurrency performance.
> And how exactly EhCache can help if a cache miss occurs where CLHM couldn't?
Oh, I didn't mean that at all. Both can help and CLHM should perform
better.
> Regarding guava - we are using r7 at the moment and I will definitely switch to MapMaker... Just wanted to make sure I'm not missing anything.
There are some unique features in CLHM which may wind up in MapMaker
someday. If you don't need those then switching is a reasonable choice
since you'll have a wider support group (not just me). Realistically,
though, I'll probably be the one digging into fixing the MapMaker bugs
anyways. :)
> The other feature I would need is grouping.
CLHM supports "weighted" values which would allow you to bound the map
by the total number of elements in the lists. For example,
map = [
key=1, value=List['a', 'b', 'c']
key=2, value=List['d', 'e']
]
would have a weighed size of 5. If the capacity was reached and
eviction of key=1 was required, then the map would reduce to a
weighted size of 2.
Depending on your needs, that may provide the group-based capacity
bounding that you're interested in.
An open item in Guava is determining exactly how a Multimap cache
would behave, since there are a few choices (evict the list entirely
or just a portion of it?). When Kevin B. has determined what the
semantics are then I will probably help the team in constructing a
concurrent implementation.
Cheers,
Ben
On Dec 17, 3:21 pm, Mindaugas Žakšauskas <
min...@gmail.com> wrote:
> Thank you for an extensive response Ben.
>
> The problem I am solving is explained here:
http://stackoverflow.com/questions/4452242/specifying-global-ehcache-...