Updating selfpopulatingcache example
Either it is too small, or there are no truly popular entries (caches work best if popularity is clustered), or the entries are expiring too fast.
The other thing to keep an eye on is how much the cache has no size limit – in theory, it could fill up your entire file system, particularly if you have your objects marked as eternal (which means they will never expire). Let’s go for a simple example: I have an Order object, which contains 3 Order Items.
In general, keeping an eye on cache hits and miss will tell you a lot about the cache effectiveness.
A low hit-to-miss ratio, for example, means that the cache is not that good.
In other words, instead of putting the actual value into the map, we put a Future (which is a wrapper for getting the value sometime in the future) into the Map.
(Note: If you have not yet become familiar with the classes introduced in the JDK 1.5, you should)By putting a Future into the map - and not our actual value - we can move the work of calling the Factory create method into the future - specifically we can move it until after the winner of the race to put the value into the map has been determined.
It's not so easy - or obvious - to do both and that's why you should use a Memoizer - and not roll your own.
I recently had to sit down and figure out exactly how it works, and thought I’d take a moment to write it up. Because open source development is more about individuals than organisations, Wotif staff members don’t really have much to do with ehcache development. You can monitor cache hits and misses in detail by turning the logging for the up.
it was initially written at Wotif, to overcome problems with the Jakarta JCS project. Since it was originally released, ehcache has grown somewhat and has a modest direct following. If you regularly see the same set of objects going in and out of the cache, you know you need a larger cache to be truly effective.
The upstream system, whether a JSP or velocity page, or interactions with a service layer or database are doing 10 times more work than they need to. It is blocking because all threads requesting the same key wait for the first thread to complete.
Once the first thread has completed the other threads simply obtain the cache entry and return.