Apache Commons logo

Commons JCS™


What jars are required by JCS?

As of version 2.0, the core of JCS (the LRU memory cache, the indexed disk cache, the TCP lateral, and the RMI remote server) only requires commons-logging.

All of the other dependencies listed on the project info page are for optional plugins.


How do I configure JCS?

By default JCS looks for a cache.ccf file in the classpath. The documentation describes how to configure the cache.


How can I configure JCS with my own properties?

You don't have to put the cache.ccf file in the classpath; instead you can do the following:

Properties props = new Properties(); props.load(/* load properties from some location defined by your app */); JCS.setConfigProperties(props);


Can JCS use system properties during configuration?

Yes. JCS will look for a system property for any name inside the delimiters ${}. Also, JCS will check to see if any property key in the cache.ccf is defined in the system properties. If so, the system value will be used.


General Questions

Is JCS faster than EHCache?

Yes. JCS is almost twice as fast as EHCache. JCS, using the default LRU Memory Cache, has proven to be nearly twice as fast as EHCache 1.2-beta4 at gets and puts. The EHCache benchmark data is unsubstantiated and very old. As such the EHCache site benchmark data is completely inaccurate. Read More


Where can I get the admin jsp?

You can download the admin jsp here .


Where can I get the source?

You can view the source here or get the source code from subversion with svn co http://svn.apache.org/repos/asf/commons/proper/jcs/trunk. The tagged releases are available with svn co. ex. https://svn.apache.org/repos/asf/commons/proper/jcs/tags/commons-jcs-2.0


How do I compile the source?

You first need to install Maven 2 The download is available at http://maven.apache.org/download.html. After installing run "mvn test" which compiles and tests the entire package. To build a jar run "mvn install".



How do I set the element attributes?

Every element put into the cache has its own set of attributes. By default elements are given a copy of the default element attributes associated with a region. You can also specify the attributes to use for an element when you put it in the cache. See Element Attributes for more information on the attributes that are available.


How do I register an element event?

Element event handlers must be added to the element attributes. See Element Event Handling for more information on how to handle element events.


Can I remove all items beginning with part of a key?

Yes, but it is somewhat expensive, since some of the auxiliaries will have to iterate over their keysets. Although all the auxiliaries honor this, it is not part of the auxiliary API. There is no method along the lines of "removeStartingWith", but all the remove methods can do it.

By default, the hierarchical key delimiter used in JCS is a colon. You cannot add a String key that ends with a colon. If you call remove with a String key that ends in a colon, everything that has a key that starts with the argument will be removed.

If your keys are in this format


And you put n objects int he cache with keys like this

"ABC:123:0" to "ABC:123:n"

then you could remove all the obejcts by calling

jcs.remove( "ABC:123:" );


Indexed Disk Cache

How do I limit the number of threads used by the disk cache?

The indexed disk cache uses an event queue for each region. By default these queues are worked by their own dedicated threads. Hence, you will have one thread per disk cache region. Although the queues kill off idle threads, you may want to limit the overall number of threads used by the queues. You can do this by telling the disk cache to use a thread pool. The configuration is described on the disk cache configuration page .


Remote Cache Server

Do I need to put my jars in the classpath of the remote server?

No. The remote server never deserializes your classes.