org.apache.slide.util
Class TxLRUObjectCache

java.lang.Object
  extended byorg.apache.slide.util.TxLRUObjectCache
Direct Known Subclasses:
ByteSizeLimitedObjectCache

public class TxLRUObjectCache
extends java.lang.Object

Transactional LRU object cache. Caches objects using a least-recently-used strategy. It provides basic isolation from other transactions and atomicity of all operations. As no locking is used (which is undesirable mainly as a cache should never block and a commit must never fail) serializability needs to be guaranteed by underlying stores.

Caution: Only global caches are limited by given size. Size of temporary data inside a transaction is unlimited.

Note: This cache has no idea if the data it caches in transactions are read from or written to store. It thus handles both access types the same way. This means read accesses are cached in transactions even though they could be cached globally. Like write accesses they will be moved to global cache at commit time.

Version:
$Revision: 1.6.2.2 $

Field Summary
protected  java.util.Map globalCache
           
protected  int hits
           
protected  java.lang.String logChannel
           
protected  Logger logger
           
protected  boolean loggingEnabled
           
protected  int misses
           
protected  java.lang.String name
           
protected  boolean noGlobalCachingInsideTx
           
protected  java.util.Map txChangeCaches
           
protected  java.util.Map txDeleteCaches
           
 
Constructor Summary
TxLRUObjectCache(int globalCacheSize, java.lang.String name, Logger logger, boolean noGlobalCachingInsideTx)
          Creates a new object cache.
 
Method Summary
 void clear()
           
 void commit(java.lang.Object txId)
           
protected  void deprune(java.util.Set set, java.lang.Object key, java.lang.String delimiter)
           
 void forget(java.lang.Object txId)
           
 java.lang.Object get(java.lang.Object txId, java.lang.Object key)
           
protected  void hit(java.lang.Object txId, java.lang.Object key)
           
protected  void log(java.lang.Object txId, java.lang.Object key, boolean hit)
           
protected  void miss(java.lang.Object txId, java.lang.Object key)
           
protected  void prune(java.util.Map map, java.lang.Object key, java.lang.String delimiter)
           
 void put(java.lang.Object txId, java.lang.Object key, java.lang.Object value)
           
 void remove(java.lang.Object txId, java.lang.Object key)
           
 void remove(java.lang.Object txId, java.lang.Object key, java.lang.String delimiter)
           Removes the object identified by key as well as any objects identified by key.toString() + delimiter.
 void rollback(java.lang.Object txId)
           
 void start(java.lang.Object txId)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

globalCache

protected java.util.Map globalCache

txChangeCaches

protected java.util.Map txChangeCaches

txDeleteCaches

protected java.util.Map txDeleteCaches

hits

protected int hits

misses

protected int misses

name

protected java.lang.String name

logger

protected Logger logger

logChannel

protected java.lang.String logChannel

loggingEnabled

protected final boolean loggingEnabled

noGlobalCachingInsideTx

protected boolean noGlobalCachingInsideTx
Constructor Detail

TxLRUObjectCache

public TxLRUObjectCache(int globalCacheSize,
                        java.lang.String name,
                        Logger logger,
                        boolean noGlobalCachingInsideTx)
Creates a new object cache. If global caching is disabled, the cache reflects isolation of underlying store as only double reads inside a single transaction will be cached. This may even increase isolation as repeatable read is guaranteed.

Parameters:
globalCacheSize - maximum size in objects of global cache or -1 to indicate no global cache shall be used
name - the name used to construct logging category / channel
logger - Slide logger to be used for logging
noGlobalCachingInsideTx - indicates global caches are enabled, but shall not be used inside transactions
Method Detail

clear

public void clear()

get

public java.lang.Object get(java.lang.Object txId,
                            java.lang.Object key)

put

public void put(java.lang.Object txId,
                java.lang.Object key,
                java.lang.Object value)

remove

public void remove(java.lang.Object txId,
                   java.lang.Object key)

remove

public void remove(java.lang.Object txId,
                   java.lang.Object key,
                   java.lang.String delimiter)

Removes the object identified by key as well as any objects identified by key.toString() + delimiter.

Example: remove(xId, "/slide/files", "-") would remove /slide/files and /slide/files-1.3 but not /slide/files/temp.

Parameters:
txId - the id of the current transaction or null if not in a transaction.
key - the key to remove from the cache.
delimiter - the delimiter to use to identify subnodes that should be removed as well.

start

public void start(java.lang.Object txId)

rollback

public void rollback(java.lang.Object txId)

commit

public void commit(java.lang.Object txId)

forget

public void forget(java.lang.Object txId)

hit

protected void hit(java.lang.Object txId,
                   java.lang.Object key)

miss

protected void miss(java.lang.Object txId,
                    java.lang.Object key)

log

protected void log(java.lang.Object txId,
                   java.lang.Object key,
                   boolean hit)

prune

protected void prune(java.util.Map map,
                     java.lang.Object key,
                     java.lang.String delimiter)

deprune

protected void deprune(java.util.Set set,
                       java.lang.Object key,
                       java.lang.String delimiter)