Updating selfpopulatingcache example

In this example, Order is an aggregate root, while Order Item is not.

updating selfpopulatingcache example-25updating selfpopulatingcache example-62updating selfpopulatingcache example-86

In this article I will describe how using Self Populating Cache class one can implement a cache with self creating objects with optional auto-updating.

In some way this example is an implementation of ideas mentioned in Ehcache documentation.

The ehcache documentation covers configuration fairly well, so I’m not going to go into it here. This complements the first-level cache, and is shared between all active Hibernate sessions. ehcache is one of the various implementations pre-packaged with Hibernate 2, and the only one packaged with Hibernate 3.

(The comments in this section refer to Hibernate 2; the behaviour in Hibernate 3 is similar enough) When you load an object in Hibernate, it will place it into the second-level cache (assuming the object is marked as cachable, etc, etc).

In the perfect world I would expect cache to be a universal pool.

I request a value for a key and would like to get it whenever it is possible and as fast as possible with just one line of code.

Often you can notice that Ehcache is used mostly like a tool that implements highly configurable maps.

Sometimes developers configure time-to-live properties, or make use of disk-store functionality, but you can rarely meet someone who has cache population/eviction process that makes sense.

When I serialise an Order Item, I end up serializing the Order, plus the other two Order Items.

Tags: , ,