JBOSS Cache for J2EE Developers
JBoss Cache enables the e-business applications to scale at peak traffic times without the cost of more powerful servers. Caching frees up valuable system resources by locally storing and distributing data across the application middle tier rather than storing it in one centralized place. Locally cached data reduces network latency, distributes system load, and eliminates bottlenecks – enabling organizations to better mange the costs associated with scaling up applications.
Types Of JBoss Cache
- Tree Cache
- Tree CacheAOP (POJO Cache)
Tree Cache
Tree Cache is a tree structured replicated transactional cache, that can be used to replicate data transactionally across multiple processes. So if we add an element to one tree, it will appear in all the trees in the cluster. A cache can either be local or replicated. Replication can be either asynchronous or synchronous. Asynchronous replication blocks the caller until all trees in a cluster have been updated where as the synchronous replication simply puts the modification(s) on the bus and returns immediately, with replication going on in the background. JBossCache can be used transactionally, meaning that if you have a transaction, JBossCache will collect all modifications and only replicate at the end of the transaction. We can configure the JBoss cache though a configuration xml file or we can set it programmatically through it’s get/set methods.
JBoss Tree Cache can be used in three modes :
- as a purely local cache, without any replication going on
- as a replicated cache, using asynchronous replication. Here there will be a primary server that updates the tree, and the updates are replicated to all backup servers either periodically, or immediately, but always in the background. It doesn’t blocks the caller that makes the modifications in the primary server.
- as a replicated cache, using synchronous replication. Here, there will be 2 phase commit protocol running across all the trees in the cluster to ensure consistency between the trees. This is used when we require a acknowledgement to make sure the modifications have been applied to all trees in the cluster after returning from a call.
JBoss TreeCacheAOP
TreeCacheAop extends the functionality of TreeCache but behaves as a true object cache providing transparent and finer-grained object mapping into internal cache. TreeCacheAop is a subclass of TreeCache, that uses instrumentation of class code to know when the state of an object has been changed. This helps to track changes to objects in the TreeCacheAop, and only replicate the changes at the end of a transaction. So if we have a big object and if we want to make some small changes in the object, so far we would have had to serialize the entire object and send it across the wire, wasting bandwidth and CPU cycles for serialization. In the TreeCache AOP case since we track changes to this object, only the changes will be replicated. So this will give us good performance, and not because AOP is so fast, but because we can reduce serialization and unnecessary network traffic.
Cache Loaders
A Cache Loader is the connection of JBossCache to a (persistent) data store. The Cache Loader is called by JBossCache to fetch data from a store when that data is not in the cache, and when modifications are made to data in the cache the Cache Loader is called to store those modifications back to the store. A CacheLoader is a class implementing org.jboss.cache.loader.CacheLoader. It is configured through a XML file.
JBossCache with a CacheLoader allows a user to maintain a bounded cache for a large backend datastore. Frequently used data is fetched from the datastore into the cache, and the least used data is evicted, in order to provide fast access to frequently accessed data. All this is configured through a XML file , and the programmer doesn't have to take care of loading and eviction.
Some of the Cache Loader implementations supported by JBoss cache are :
FileCacheLoader : This implementation uses the file system to store and retrieve data. JBossCache nodes are mapped to directories, subnodes to subdirectories etc. Attributes of a node are mapped to a file data inside the directory.
JDBCCacheLoader : This implementation uses the relational database as the persistent storage.
ClusteredCacheLoader :This implementation queries the rest of the cluster, treating other servers' in-memory state as a data store.
0 Comments:
Post a Comment