Wednesday, September 24, 2008

Why Tree Structured Cache is implemented in JBoss Cache?

The first version of TreeCache was essentially a single HashMap that replicated. However, the decision was taken to go with a tree structured cache because
(a) it is more flexible and efficient and
(b) a tree can always be reduced to a map, thereby offering both possibilities.

The efficiency argument was driven by concerns over replication overhead, and was that a value itself can be a rather sophisticated object, with aggregation pointing to other objects, or an object containing many fields. A small change in the object would therefore trigger the entire object (possibly the transitive closure over the object graph) to be serialized and propagated to the other nodes in the cluster. With a tree, only the modified nodes in the tree need to be serialized and propagated. This is not necessarily a concern for TreeCache, but is a vital requirement for PojoCache.

With POJO cache, the feature of object cache by reachability is well supported by the tree structured cache. Object cache by reachability is basically recursive object mapping into the cache store. For example, if a POJO has a reference to another advised POJO, PojoCache will transparently manage the sub-object states as well. During the initial putObject() call, PojoCache will traverse the object tree and map it accordingly to the internal TreeCache nodes.

Another similar research can be found in the following paper:
http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.27.2819