MRUMemoryStore in Apache Cocoon
http://xml.apache.org/http://www.apache.org/http://www.w3.org/

Main
User Documentation
Concepts
Overview
Sitemap
Views
Caching
Actions
Matchers and Selectors
Entity Catalogs
MRUMemoryStore
StoreJanitor

Goal

This document explains how the MRUMemoryStore under Apache Cocoon executes.


Overview

The MRUMemoryStore was developed to provide a standard algorithm to store data in memory. For web-based applications the MRU (Most Recently Used) algorithm is very suitable, because the object most frequently accessed is always on "top".

If configured accordingly, the objects are also swapped to the filesystem, to hold them in a persistent state over JVM restarts.


Implementation
Storing in memory

The heart of the MRUMemoryStore ist combination of a LinkedList and a HashMap:

The LinkedList provides the queue mechanism, and the entries in the LinkedList contain the key to the data in the HashMap. When calling the store() method a new entry to the front of the list is inserted. If the list is already full, the free() method is called and the oldest, the last one in the LinkedList, data entry is removed from the HashMap and from the LinkedList. When calling the get() method, the store returns the object by key and inserts the requested key on the top of the LinkedList. This implementation keeps the most recent used objects in the store and provides the best use of the machines memory.


Storing on the filesystem

Storing in Memory is fast, but when the JVM restarts your processed Objects are gone and must be processed again, although they didn't have changed. What a waste of CPU time.

If configured, the MRUMemoryStore will keep your objects not only in memory, rather also on the filesystem. When calling the store() method, objects are pushed on a stack, which is processed by a "writerthread" in the background. This thread pops the object from the stack and serialize it to the fs. So the objects are asynchron written to the filesystem, to keep the performance fast. The thread sleeps and awakes only, when one or more objects are pushed on the stack. But only CacheStreamObject's and CacheEventObject's in the moment are stored on the filesystem.

If you restart your application memory is clean. When you request an object with the get() method the filesystem is checked if the requested object is available, deserialize it and give it back to the caller. After all the store() method is called and the deserialized object is stored in memory for further usage.


Background threads

The WriterThread is notified when an object is pushed on the stack and serialize the objects in the stack on the filesystem.



Configuration of the MRUMemoryStore
  
  <event-cache class="org.apache.cocoon.components.store.MRUMemoryStore">
     <parameter name="maxobjects" value="100"/>
     <parameter name="threadpriority" value="5"/>
     <parameter name="filesystem" value="true"/>
  </event-cache>
  
  

If you want to use the MRUMemoryStore as your EventCache:

  1. <event-cache class="org.apache.cocoon.components.store.MRUMemoryStore">: Assigns the MRUMemoryStore as the actual EventCache.
  2. <parameter name="maxobjects" value="100"/>: Indicates how many objects will be hold in the cache. When the number of maxobjects has been reached. The last object in the cache will be thrown out.
  3. <parameter name="threadpriority" value="5"/>: Indicates the priority of the background threads. 1 is the lowest priority and 10 is the highest.
  4. <parameter name="filesystem" value="true"/>: Turns the filesystem storage for objects on or off.

Copyright © 1999-2001 The Apache Software Foundation. All Rights Reserved.