org.apache.slide.util
Class ByteSizeLimitedObjectCache
java.lang.Object
org.apache.slide.util.TxLRUObjectCache
org.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.
- Version:
- $Revision: 1.1.2.1 $
- Author:
- Oliver Zeigermann
- See Also:
TxLRUObjectCache
Constructor Summary |
ByteSizeLimitedObjectCache(int globalCacheSize,
int txCacheSize,
long globalByteSize,
long txByteSize,
long maxByteSizePerEntry,
java.lang.String name,
Logger logger)
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 java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
MAX_FREEING_TRIES
protected static final int MAX_FREEING_TRIES
- See Also:
- Constant Field Values
globalByteSize
protected long globalByteSize
txCacheSize
protected int txCacheSize
txByteSize
protected long txByteSize
maxByteSizePerEntry
protected long maxByteSizePerEntry
ByteSizeLimitedObjectCache
public ByteSizeLimitedObjectCache(int globalCacheSize,
int txCacheSize,
long globalByteSize,
long txByteSize,
long maxByteSizePerEntry,
java.lang.String name,
Logger logger)
- 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.
- Parameters:
globalCacheSize
- maximum size in objects of global cachetxCacheSize
- maximum size in objects for local transaction cacheglobalByteSize
- maximum size in bytes of global cachetxByteSize
- maximum size in bytes for local transaction cachemaxByteSizePerEntry
- maximum size of a single cache entry in bytesname
- the name used to construct logging category / channellogger
- Slide logger to be used for logging
clear
public void clear()
- Overrides:
clear
in class TxLRUObjectCache
canCache
public boolean canCache(java.lang.Object txId,
long byteSize)
put
public void put(java.lang.Object txId,
java.lang.Object key,
java.lang.Object value,
long byteSize)
start
public void start(java.lang.Object txId)
- Overrides:
start
in class TxLRUObjectCache
commit
public void commit(java.lang.Object txId)
- Overrides:
commit
in class TxLRUObjectCache