Apache Commons logo

Commons JCS™

Frequently Asked Questions

Configuration

  1. What jars are required by JCS?
  2. How do I configure JCS?
  3. How can I configure JCS with my own properties?
  4. Can JCS use system properties during configuration?
  5. How do I shut down JCS properly?

General Questions

  1. Is JCS faster than EHCache?
  2. Where can I get the admin jsp?
  3. Where can I get the source?
  4. How do I compile the source?

Elements

  1. How do I set the element attributes?
  2. How do I register an element event?
  3. Can I remove all items beginning with part of a key?

Indexed Disk Cache

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

Remote Cache Server

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

Configuration

What jars are required by JCS?

As of version 3.0, the core of JCS (the LRU memory cache, the indexed disk cache, the TCP lateral, and the RMI remote server) have no mandatory dependencies.

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

[top]


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.

[top]


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);

[top]


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.

[top]


How do I shut down JCS properly?

As of version 3.0, you can simply call

JCS.shutdown();

[top]

General Questions

Is JCS faster than EHCache?

Yes. JCS is almost twice as fast as EHCache. JCS 1.2.7.0, 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

[top]


Where can I get the admin jsp?

You can download the admin jsp here .

[top]


Where can I get the source?

See the information about the Source Repository

[top]


How do I compile the source?

You first need to install Maven After installing run "mvn test" which compiles and tests the entire package. To build a jar run "mvn package".

[top]

Elements

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.

[top]


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.

[top]


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

TYPE:SOURCE:OBJECT

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:" );

[top]

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 .

[top]

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.

[top]