Class ByteSizeLimitedObjectCache

  extended byorg.apache.slide.util.TxLRUObjectCache
      extended byorg.apache.slide.util.ByteSizeLimitedObjectCache

public class ByteSizeLimitedObjectCache
extends TxLRUObjectCache

Transactional LRU byte counting object cache. Caches objects using a least-recently-used strategy. Asserts a given overall size of all cached objects does not exceed a specified limit. 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. Note: Unlike TxLRUObjectCache this cache also limits the size of temporary caches inside transactions. This is necessary as size of bytes in a transaction can become really big. In case an entry can not be cached inisde a transaction it will be marked as invalid after commit of that tx.

$Revision: 1.5 $
See Also:

Nested Class Summary
protected  class ByteSizeLimitedObjectCache.SizeCountingLRUMap
Field Summary
protected  long globalByteSize
protected static int MAX_FREEING_TRIES
protected  long maxByteSizePerEntry
protected  long txByteSize
protected  int txCacheSize
Fields inherited from class org.apache.slide.util.TxLRUObjectCache
globalCache, hits, logChannel, logger, loggingEnabled, misses, name, noGlobalCachingInsideTx, txChangeCaches, txDeleteCaches
Constructor Summary
ByteSizeLimitedObjectCache(int globalCacheSize, int txCacheSize, long globalByteSize, long txByteSize, long maxByteSizePerEntry, java.lang.String name, Logger logger, boolean noGlobalCachingInsideTx)
          Creates a new object cache.
Method Summary
 boolean canCache(java.lang.Object txId, long byteSize)
 void clear()
 void commit(java.lang.Object txId)
 void put(java.lang.Object txId, java.lang.Object key, java.lang.Object value, long byteSize)
 void start(java.lang.Object txId)
Methods inherited from class org.apache.slide.util.TxLRUObjectCache
deprune, forget, get, hit, log, miss, prune, put, remove, remove, rollback
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Detail


protected static final int MAX_FREEING_TRIES
See Also:
Constant Field Values


protected long globalByteSize


protected int txCacheSize


protected long txByteSize


protected long maxByteSizePerEntry
Constructor Detail


public ByteSizeLimitedObjectCache(int globalCacheSize,
                                  int txCacheSize,
                                  long globalByteSize,
                                  long txByteSize,
                                  long maxByteSizePerEntry,
                                  java.lang.String name,
                                  Logger logger,
                                  boolean noGlobalCachingInsideTx)
Creates a new object cache. The maximum cache size can be configured for local transaction caches as well as on a global level. The idea of having a maximum size in bytes per entry is to prevent a large entry to displace many small entries.

globalCacheSize - maximum size in objects of global cache
txCacheSize - maximum size in objects for local transaction cache
globalByteSize - maximum size in bytes of global cache
txByteSize - maximum size in bytes for local transaction cache
maxByteSizePerEntry - maximum size of a single cache entry in bytes
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


public void clear()
clear in class TxLRUObjectCache


public boolean canCache(java.lang.Object txId,
                        long byteSize)


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


public void start(java.lang.Object txId)
start in class TxLRUObjectCache


public void commit(java.lang.Object txId)
commit in class TxLRUObjectCache