JBoss Community

Shotoku renewable cache

The renewable cache is designed to fit one use case: when you need to store some data in a cache, and update it periodically in the background. For example, imagine you have a large configuration file, which determines the layout of your web page. You have to:

  • on every web page request, read the parsed configuration data, and
  • from time to time, update the configuration data, basing on persistent store (filesystem, database, etc ...).
Of course, making the updates a blocking operation on a web page request isn't acceptable. That is where you can use Shotoku Renewable Cache, which will update the values held in cache in the background, on regular intervals of time.

As the backing cache, a JBoss Cache tree cache is used (any configured by the user). The renewable cache operates on units called "cache items". Each cache item is bound with one FQN in the associated tree cache. A cache item then creates and stores objects in tree cache keys (attributes).

To create a cache item, you have to implement an interface CacheItemDataSource, which has two functions:

  • init(key) - this is called when a value for a key is requested for the first time. The task of this function is to return an initial value. It is the only blocking operation.
  • update(key, currentValue) - this is called when a key is updated. The current value is supplied, and the function may return either a new value, or keep the old value in the cache. This operation is performed by a daemon thread, on specified intervals of time.

Then you just need to register you cache item datasource, and you can read data from it, using a simple get(key) function. To see an example of a cache item and it's usage, click here.

Shotoku Renewable Cache also comes with an administration panel, which lets you change the configuration (for example update intervals) and monitor the state of the updates (when keys where last updated). Thanks to Ajax4JSF, you don't have to refresh the panel to check if anything has changed: all important parts are refreshed automatically.

Also, in the administration console you can see alerts when:

  • a key isn't updated for too long
  • a key is in update for too long (if this is the case, you can reset the key's update status, so that the service tries to update it again)
  • an exception occurred during a key update (the exception will also be logged in the AS log, but only once, and if subsequent updates throw exceptions again, they will be suppressed, until the original alert is "cleared" in the administration console. This way your log will stay relatively clean.)
For all of these alerts, you can configure e-mail notifications. For example, if you get an alert that a key is not updated for too long, it may mean that the interval of updates is too short, that there are not enough update threads or, if the data is read from a remote host, that the host is down.

Check also:

One of the places where the renewable cache is used, is in the software running this site. It was developed as a support project for JBoss Labs, which works on JBoss Portal.

Shotoku Renewable Cache works with JBoss AS 4.0.x and JBoss Cache 1.4.x.

Here's how the administration panel looks:

JBoss Blog Portlet

Javarsovia, static analysis and annotations
Posted on Jul 2, 2009 3:15:32 PM by Adam Warski.

If you’ll be in Warsaw this weekend, and if you speak polish, be sure not to miss Javarsovia, a one-day conference organized by the Warsaw JUG. I am giving a talk there about how you can use annotatio...

Envers on Jazoon
Posted on Jun 21, 2009 5:15:57 AM by Adam Warski.

If you’ll be attending Jazoon next week, be sure not to miss the Envers presentation! It will take place on Wednesday (24th July), at 4pm (here are the presentation details). I’ll be attending the who...

Envers 1.2.1.GA released
Posted on Jun 6, 2009 4:44:18 AM by Adam Warski.

Yesterday I uploaded a new release of Envers, 1.2.1.GA. It is mainly a bugfix release, but there is also one new feature. You can now access the current revision entity directly using AuditReader, wit...

StaticAccess detector for FindBugs
Posted on May 11, 2009 1:30:19 PM by Adam Warski.

The StaticAccess detector is a FindBugs plugin, which lets you verify that methods do not rely on static (global) state, that is, that they don’t read or write static variables which aren’t constant. ...

New features in Typestate Checker
Posted on Apr 14, 2009 2:51:35 PM by Adam Warski.

I’ve uploaded a new version (0.2) of the typestate checker (for an introduction, see this blog post), which contains bug fixes and much improved exception handling. The binaries, source code and insta...

Envers 1.2.0.GA in Maven repository; JSR308 typestate and maven plugin in GIT
Posted on Mar 11, 2009 12:21:27 PM by Adam Warski.

The recently released Envers 1.2.0.GA finally made it to the JBoss Maven repository; you can find it here: http://repository.jboss.org/maven2/org/jboss/envers/jboss-envers/1.2.0.GA-hibernate-3.3/ Also...

Envers 1.2.0.GA released!
Posted on Mar 5, 2009 12:09:08 PM by Adam Warski.

Today Envers 1.2.0.GA has been released! It is a Hibernate 3.3 compatible version of the newest Envers codebase, which will be included as a module in Hibernate 3.5. You can download it here, and find...

JSR308 Checkers Maven2 plugin
Posted on Feb 4, 2009 1:11:54 PM by Adam Warski.

I’ve written a prototype JSR308 Checkers Maven2 plugin. You can use the plugin to run any checker on the sources of your module(s). The JSR308 compiler, and in effect also the checkers, are run in a s...

Envers in Anvers!
Posted on Dec 4, 2008 1:29:22 PM by Adam Warski.

December came, so it’s time for Devoxx! (formerly JavaPolis) If you are planning to visit Antwerp this year, make sure to come and see the Envers presentation (first conference day, 3pm)! I will expla...

Typestate checker - introduction
Posted on Nov 17, 2008 1:17:29 PM by Adam Warski.

When dealing with mutable objects in Java, we quite often see that “states” of the class considered emerge. The (abstract) “state” depends of course on the content of the fields of the object. When me...