What is a cache loader?
A cache loader is the connection of JBoss Cache to a (persistent) data store. The cache loader is called by JBoss Cache 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.
In conjunction with eviction policies, JBoss Cache with a cache loader 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. This is all configured through XML, and the programmer doesn't have to take care of loading and eviction.
JBoss Cache currently ships with several cache loader implementations, including:
Is the FileCacheLoader recommended for production use?
No, it is not. The FileCacheLoader has some severe limitations which restrict it's use in a production environment, or if used in such an environment, it should be used with due care and sufficient understanding of these limitations.
As a rule of thumb, it is recommended that the FileCacheLoader not be used in a highly concurrent, transactional or stressful environment, and it's use is restricted to testing.
Can writing to cache loaders be asynchronous?
Yes. Set the async attrobute to true. See the JBoss Cache User Guide for a more detailed discussion. By default though, all cache loader writes are synchronous and will block.
Can I write my own cache loader ?
Yes. A cache loader is a class implementing org.jboss.cache.loader.CacheLoader or extending org.jboss.cache.loader.AbstractCacheLoader . It is configured via the XML file (see JBoss Cache User Guide).
Does a cache loader have to use a persistent store ?
No, a cache loader could for example fetch (and possibly store) its data from a webdav-capable webserver. Another example is a caching proxy server, which fetches contents from the web. Note that an implementation of CacheLoader may not implement the 'store' functionality in this case, but just the 'load' functionality.
Do I have to pay to use Oracle's Berkeley DB CacheLoader?
Not if you use it only for personal use. As soon as you distribute your product with BdbjeCacheLoader, you have to purchase a commercial license from Oracle. See details at http://www.sleepycat.com/jeforjbosscache .
Can I use more than one cache loader?
Yes. Within the CacheLoaderConfiguration XML element (see user guide chapter on cache loaders) you can describe several cache loaders. The impact is that the cache will look at all of the cache loaders in the order they've been configured, until it finds a valid, non-null element of data. When performing writes, all cache loaders are written to (except if the ignoreModifications element has been set to true for a specific cache loader.
Can I migrate a JDBCacheLoader or FileCacheLoader based cache store containing data formatted with JBoss Cache 1.x.x to JBoss Cache 2.0 format?
Yes. See "Transforming Cache Loaders" section within the "Cache Loaders" section located in the JBoss Cache users guide.