org.apache.cocoon.components.store.impl
Class MRUMemoryStore

java.lang.Object
  extended byorg.apache.cocoon.components.store.impl.MRUMemoryStore
All Implemented Interfaces:
Store
Direct Known Subclasses:
DefaultStore, DefaultTransientStore

public class MRUMemoryStore
extends Object
implements Store

This class provides a cache algorithm for the requested documents. It combines a HashMap and a LinkedList to create a so called MRU (Most Recently Used) cache. Adapted from org.apache.excalibur.store.impl.MRUMemoryStore

Version:
$Id: MRUMemoryStore.html 1304280 2012-03-23 11:18:01Z ilgrosso $

Field Summary
protected  boolean persistent
           
 
Fields inherited from interface org.apache.excalibur.store.Store
PERSISTENT_STORE, ROLE, TRANSIENT_STORE
 
Constructor Summary
MRUMemoryStore()
           
 
Method Summary
 void clear()
          Clear the Store of all elements
 boolean containsKey(Object key)
          Indicates if the given key is associated to a contained object.
 void destroy()
          Dispose the component
 void free()
          Frees some of the fast memory used by this store.
 Object get(Object key)
          Get the object associated to the given unique key.
 Log getLogger()
           
 void hold(Object key, Object value)
          This method holds the requested object in a HashMap combined with a LinkedList to create the MRU.
 void init()
          Initialize the MRUMemoryStore.
 Enumeration keys()
          Returns the list of used keys as an Enumeration.
 void remove(Object key)
          Remove the object associated to the given key.
 void setLogger(Log l)
           
 void setMaxObjects(int maxobjects)
          Indicates how many objects will be held in the cache.
 void setPersistentStore(Store persistentStore)
          Set to keep objects persisted after container shutdown
 void setStoreJanitor(StoreJanitor storeJanitor)
           
 void setUsePersistentStore(boolean persistent)
           
 int size()
          Returns count of the objects in the store, or -1 if could not be obtained.
 void store(Object key, Object value)
          Store the given object in a persistent state.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

persistent

protected boolean persistent
Constructor Detail

MRUMemoryStore

public MRUMemoryStore()
Method Detail

getLogger

public Log getLogger()

setLogger

public void setLogger(Log l)

setMaxObjects

public void setMaxObjects(int maxobjects)
Indicates how many objects will be held in the cache. When the number of maxobjects has been reached. The last object in the cache will be thrown out. (Default: 100 objects)

Parameters:
maxobjects -

setUsePersistentStore

public void setUsePersistentStore(boolean persistent)
Parameters:
persistent -

setPersistentStore

public void setPersistentStore(Store persistentStore)
Set to keep objects persisted after container shutdown

Parameters:
persistentStore -

setStoreJanitor

public void setStoreJanitor(StoreJanitor storeJanitor)
Parameters:
storeJanitor -

init

public void init()
          throws Exception
Initialize the MRUMemoryStore.

Throws:
Exception
ParameterException

destroy

public void destroy()
Dispose the component


store

public void store(Object key,
                  Object value)
Store the given object in a persistent state. It is up to the caller to ensure that the key has a persistent state across different JVM executions.

Specified by:
store in interface Store
Parameters:
key - The key for the object to store
value - The object to store

hold

public void hold(Object key,
                 Object value)
This method holds the requested object in a HashMap combined with a LinkedList to create the MRU. It also stores objects onto the filesystem if configured.

Parameters:
key - The key of the object to be stored
value - The object to be stored

get

public Object get(Object key)
Get the object associated to the given unique key.

Specified by:
get in interface Store
Parameters:
key - The key of the requested object
Returns:
the requested object

remove

public void remove(Object key)
Remove the object associated to the given key.

Specified by:
remove in interface Store
Parameters:
key - The key of to be removed object

clear

public void clear()
Clear the Store of all elements

Specified by:
clear in interface Store

containsKey

public boolean containsKey(Object key)
Indicates if the given key is associated to a contained object.

Specified by:
containsKey in interface Store
Parameters:
key - The key of the object
Returns:
true if the key exists

keys

public Enumeration keys()
Returns the list of used keys as an Enumeration.

Specified by:
keys in interface Store
Returns:
the enumeration of the cache

size

public int size()
Returns count of the objects in the store, or -1 if could not be obtained.

Specified by:
size in interface Store

free

public void free()
Frees some of the fast memory used by this store. It removes the last element in the store.

Specified by:
free in interface Store


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