org.apache.jackrabbit.core.state
Class MLRUItemStateCache

java.lang.Object
  extended by org.apache.jackrabbit.core.state.MLRUItemStateCache
All Implemented Interfaces:
Cache, ItemStateCache

public class MLRUItemStateCache
extends Object
implements ItemStateCache, Cache

An ItemStateCache implementation that internally uses a LinkedMap to maintain a cache of ItemState objects. The cache uses a rough estimate of the memory consumption of the cached item states for calculating the maximum number of entries. The oldest entries are flushed once the cache size has exceeded a certain limit.

TODO rename class to something more appropriate, e.g. FIFOItemSateCache since it doesn't use a LRU eviction policy anymore.


Field Summary
static int DEFAULT_MAX_MEM
          default maximum memory to use
 
Constructor Summary
MLRUItemStateCache()
          Constructs a new, empty ItemStateCache with a maximum amount of memory of DEFAULT_MAX_MEM.
 
Method Summary
 void cache(ItemState state)
          Stores the specified ItemState object in the map using its ItemId as the key.
 void dispose()
          Informs the cache that it is no longer in use.
 void evict(ItemId id)
          Removes the ItemState object with the specified id from this cache if it is present.
 void evictAll()
          Clears all entries from this cache.
 long getAccessCount()
          Get the number of accesses (get or set) until resetAccessCount was called.
 long getMaxMemorySize()
          Get the current limit.
 long getMemoryUsed()
          Get the amount of used memory.
 boolean isCached(ItemId id)
          Returns true if this cache contains an ItemState object with the specified id.
 boolean isEmpty()
          Returns true if this cache contains no entries.
 void resetAccessCount()
          Reset the access counter.
 ItemState retrieve(ItemId id)
          Returns the ItemState object with the specified id if it is present or null if no entry exists with that id.
 ItemState[] retrieveAll()
          Returns all the cached item states.
 void setAccessListener(CacheAccessListener listener)
          Set the cache access listener.
 void setMaxMemorySize(long size)
          Set the new memory limit.
 void update(ItemId id)
          Informs the cache that the item was modified and the cache might need to recalculate the items caching weight.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_MAX_MEM

public static final int DEFAULT_MAX_MEM
default maximum memory to use

See Also:
Constant Field Values
Constructor Detail

MLRUItemStateCache

public MLRUItemStateCache()
Constructs a new, empty ItemStateCache with a maximum amount of memory of DEFAULT_MAX_MEM.

Method Detail

isCached

public boolean isCached(ItemId id)
Returns true if this cache contains an ItemState object with the specified id.

Specified by:
isCached in interface ItemStateCache
Parameters:
id - id of ItemState object whose presence should be tested.
Returns:
true if there's a corresponding cache entry, otherwise false.

retrieve

public ItemState retrieve(ItemId id)
Returns the ItemState object with the specified id if it is present or null if no entry exists with that id.

Specified by:
retrieve in interface ItemStateCache
Parameters:
id - the id of the ItemState object to be returned.
Returns:
the ItemState object with the specified id or or null if no entry exists with that id

retrieveAll

public ItemState[] retrieveAll()
Returns all the cached item states.

Specified by:
retrieveAll in interface ItemStateCache
Returns:
newly allocated item state array

update

public void update(ItemId id)
Informs the cache that the item was modified and the cache might need to recalculate the items caching weight.

Specified by:
update in interface ItemStateCache
Parameters:
id - the id of the item that was modified.

cache

public void cache(ItemState state)
Stores the specified ItemState object in the map using its ItemId as the key.

Specified by:
cache in interface ItemStateCache
Parameters:
state - the ItemState object to cache

evict

public void evict(ItemId id)
Removes the ItemState object with the specified id from this cache if it is present.

Specified by:
evict in interface ItemStateCache
Parameters:
id - the id of the ItemState object which should be removed from this cache.

evictAll

public void evictAll()
Clears all entries from this cache.

Specified by:
evictAll in interface ItemStateCache

isEmpty

public boolean isEmpty()
Returns true if this cache contains no entries.

Specified by:
isEmpty in interface ItemStateCache
Returns:
true if this cache contains no entries.

getAccessCount

public long getAccessCount()
Get the number of accesses (get or set) until resetAccessCount was called.

Specified by:
getAccessCount in interface Cache
Returns:
the count

getMaxMemorySize

public long getMaxMemorySize()
Get the current limit.

Specified by:
getMaxMemorySize in interface Cache
Returns:
the size in bytes

getMemoryUsed

public long getMemoryUsed()
Get the amount of used memory.

Specified by:
getMemoryUsed in interface Cache
Returns:
the size in bytes

resetAccessCount

public void resetAccessCount()
Reset the access counter.

Specified by:
resetAccessCount in interface Cache

setMaxMemorySize

public void setMaxMemorySize(long size)
Set the new memory limit.

Specified by:
setMaxMemorySize in interface Cache
Parameters:
size - the size in bytes

setAccessListener

public void setAccessListener(CacheAccessListener listener)
Set the cache access listener. Only one listener per cache is supported.

Specified by:
setAccessListener in interface Cache
Parameters:
listener - the new listener

dispose

public void dispose()
Informs the cache that it is no longer in use.

Specified by:
dispose in interface ItemStateCache


Copyright © 2004-2009 The Apache Software Foundation. All Rights Reserved.