org.apache.cocoon.cache
Class LRUCache

java.lang.Object
  |
  +--org.apache.cocoon.cache.LRUCache

public class LRUCache
extends java.lang.Object
implements Configurable, Cache

A class to encapsulate the caching of preprocessed XML files.

Version:
$Revision: 1.2 $ $Date: 1999/03/24 16:05:56 $
Author:
Greg Ritter

Field Summary
private  java.util.Hashtable cache
           
private  java.lang.String directory
           
private  int maxDiskObjects
           
private  int maxMemObjects
           
 
Constructor Summary
LRUCache()
           
 
Method Summary
 boolean containsKey(java.lang.Object key)
          Check if the specified key exists in this Cache.
private  boolean containsKeyOnDisk(java.lang.Object key)
          Check if the specified key exists in cache on disk.
 java.lang.Object get(java.lang.Object key)
          Get a value from the cache for the specified key Object.
private  java.lang.Object getFromDisk(java.lang.Object key)
          Get a cached Object from disk for the specified key.
 int getMaxDiskSize()
          Get the maximum number of objects this cache can hold on disk.
 int getMaxMemSize()
          Get the maximum number of objects this cache can hold in memory.
 int getSize()
          Get the number of objects currently in cache.
private  int getSizeOnDisk()
          Get the number of cached objects on disk for this cache.
 void init(Configurations conf)
          Initialize this cache using the configuration information.
 void put(java.lang.Object key, java.lang.Object value)
          Put a key/value pair in the cache.
private  void putLRUToDisk()
          Put the least recently used cache pair to disk.
private  void putToDisk(java.lang.Object key)
          Put the object with the specified key to the disk cache.
 java.lang.String toString()
          Return a textual identifier for this cache.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, wait, wait, wait
 

Field Detail

cache

private java.util.Hashtable cache

maxMemObjects

private int maxMemObjects

maxDiskObjects

private int maxDiskObjects

directory

private java.lang.String directory
Constructor Detail

LRUCache

public LRUCache()
Method Detail

init

public void init(Configurations conf)
Initialize this cache using the configuration information.
Specified by:
init in interface Configurable
Parameters:
conf - the configuration information

put

public void put(java.lang.Object key,
                java.lang.Object value)
Put a key/value pair in the cache. If necessary, move the least recently used cache pair to disk to make room for the new pair.
Specified by:
put in interface Cache
Parameters:
key - the key Object of the key/value pair
value - the value Object of the key/value pair

get

public java.lang.Object get(java.lang.Object key)
Get a value from the cache for the specified key Object. If necessary, get the value from disk.
Specified by:
get in interface Cache
Parameters:
key - the key Object
Returns:
the value for the key, or null if the key was not in the cache

containsKey

public boolean containsKey(java.lang.Object key)
Check if the specified key exists in this Cache.
Specified by:
containsKey in interface Cache
Parameters:
key - the key to check for
Returns:
true if the key exists in the cache, false otherwise

getSize

public int getSize()
Get the number of objects currently in cache.
Specified by:
getSize in interface Cache
Returns:
the number of objects currently in cache

getMaxMemSize

public int getMaxMemSize()
Get the maximum number of objects this cache can hold in memory.
Specified by:
getMaxMemSize in interface Cache
Returns:
the number of objects this cache can hold in memory

getMaxDiskSize

public int getMaxDiskSize()
Get the maximum number of objects this cache can hold on disk.
Specified by:
getMaxDiskSize in interface Cache
Returns:
the number of objects this cache can hold on disk

putLRUToDisk

private void putLRUToDisk()
Put the least recently used cache pair to disk.

putToDisk

private void putToDisk(java.lang.Object key)
Put the object with the specified key to the disk cache.
Parameters:
key - the key of the object to cache to disk

getFromDisk

private java.lang.Object getFromDisk(java.lang.Object key)
Get a cached Object from disk for the specified key.
Parameters:
key - the key Object
Returns:
the value Object for the specified key

containsKeyOnDisk

private boolean containsKeyOnDisk(java.lang.Object key)
Check if the specified key exists in cache on disk.
Parameters:
key - the key to check for
Returns:
true if the key exists on disk, false otherwise

getSizeOnDisk

private int getSizeOnDisk()
Get the number of cached objects on disk for this cache.
Returns:
the number of cached objects on disk for this cache

toString

public java.lang.String toString()
Return a textual identifier for this cache.
Overrides:
toString in class java.lang.Object

Copyright (c) 1998 The Java Apache Project