« JBossCache - TreeCache | Main | Jofti »

Whirlycache





Whirlycache is a fast, configurable in-memory object cache java. It can be used, for example, to speed up a website or an application by caching objects that would otherwise have to be created by querying a database or by another expensive procedure. From the testing that we have done, it appears to be faster than any other Java cache that we have been able to inspect.

Whirlycache Benchmark Results.

Whirlycache Design

Whirlycache is built around several design principles that differ from other cache implementations:

1. Require synchronization as infrequently as possible
2. Do as little as possible in the insertion and retrieval operations
3. Soft limits are acceptable for many applications
4. Disk overflow becomes a bad idea very quickly

Many attributes of Whirlycache are configurable in an XML file, but the most important components of the cache are the Backend, the Tuner, and the Policy.

We support pluggable backend implementations that need to implement the ManagedCache interface (which is a subinterface of java.util.Map, although not all the methods of Map need to be implemented). We currently support two backends: ConcurrentHashMap and FastHashMap. You can decide which one suits your application best. In our testing, it's hard to tell which one comes out on top all of the time. If you need to, you can even implement your own backed by implementing the ManagedCache interface.

The Tuner is a background thread that performs cache maintenance activites specified in the configured Policy implementation. One Tuner thread per cache is created and it is configured to run every n seconds. It depends on your application, but you definitely don't want to run the Tuner too often since it will only serve to burden the system unnecessarily. If your data doesn't change a lot, you could simply configure it to run every few minutes.

The purpose of the Tuner is to perform activities that would otherwise be performed by the insertion and retrieval operations (which we want to keep very lean and fast). The Tuner expires elements from the cache based on the configured Policy and the configured maxsize of the cache. Please keep in mind that the maxsize value is a softlimit that can be exceeded in between Tuner runs (remember that these only run every n seconds). When the Tuner thread runs, it will prune the cache down to the maxsize according to the rules of the Policy.

This last point is particularily relevant to those who may be inserting large objects into Whirlycache. For example, if you decide to cache 10Mb PDF files in memory, be sure that your Cache has an appropriately configured max-size and that you run the Tuner frequently enough to account for any activity that could result in something potentially disastrous such as ninety 10Mb files being inserted all of a sudden. If you don't have enough memory allocated to your JVM, you will inevitably get an exception complaining about a lack of memory! The max-size declaration in the whirlycache.xml file tells the configured Policy class to trim the Cache to n elements every time it runs. There is nothing to prevent you from successfully inserting n+1 objects into the cache. It will work, assuming you don't run out of memory.

The Policy defines the set of rules for removing elements from a cache. You can specify a different Policy implementation per named cache in the whirlycache.xml configuration file. Currently, we offer FIFO, LFU and LRU.

Configuration & Installation
To use Whirlycache, simply download the latest distribution and unzip it. Then, copy all of the supplied jar files in your classpath. Finally, you will need to supply a whirlycache.xml file in your classpath as well. You need to properly configure the whirlycache.xml file according to your needs, but we have supplied you with reasonable default values that you can change later if you need to.
Here is a sample whirlycache.xml configuration file.

Whirlycache License

Project Home Page
https://whirlycache.dev.java.net/

Whirlycache Source Code Download
https://whirlycache.dev.java.net/source/browse/whirlycache/

Download Whirlycache
https://whirlycache.dev.java.net/downloads/whirlycache-1.0.1.zip

TrackBack

TrackBack URL for this entry:
http://freejdk.org/mt-tb.cgi/57