Package org.apache.jackrabbit.core.state
Class ItemStateReferenceCache
- java.lang.Object
-
- org.apache.jackrabbit.core.state.ItemStateReferenceCache
-
- All Implemented Interfaces:
ItemStateCache
public class ItemStateReferenceCache extends Object implements ItemStateCache
ItemStateReferenceCacheinternally consists of 2 components:- an
ItemStateReferenceMapserving as the primary (or main) cache; it holds weak references toItemStateinstances. ThisItemStateCacheimplementation directly represents the contents of the primary cache, i.e.isCached(ItemId),retrieve(ItemId)},isEmpty()etc. only refer to the contents of the primary cache. - an
ItemStateCacheimplementing a custom eviction policy and serving as the secondary (or auxiliary) cache; entries that are automatically flushed from this secondary cache through its eviction policy (LRU, etc.) will be indirectly flushed from the primary (reference) cache by the garbage collector if they are thus rendered weakly reachable.
This implementation of ItemStateCache is thread-safe.
-
-
Constructor Summary
Constructors Constructor Description ItemStateReferenceCache(ItemStateCache cache)Creates a newItemStateReferenceCachethat uses the specifiedItemStateCacheinstance as internal secondary cache.ItemStateReferenceCache(ItemStateCacheFactory cacheFactory)Creates a newItemStateReferenceCachethat uses aMLRUItemStateCacheinstance as internal cache.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcache(ItemState state)Stores the specifiedItemStateobject in the map using itsItemIdas the key.voiddispose()Informs the cache that it is no longer in use.voidevict(ItemId id)Removes theItemStateobject with the specified id from this cache if it is present.voidevictAll()Clears all entries from this cache.booleanisCached(ItemId id)Returnstrueif this cache contains anItemStateobject with the specifiedid.booleanisEmpty()Returnstrueif this cache contains no entries.ItemStateretrieve(ItemId id)Returns theItemStateobject with the specifiedidif it is present ornullif no entry exists with thatid.ItemState[]retrieveAll()Returns all the cached item states.
-
-
-
Constructor Detail
-
ItemStateReferenceCache
public ItemStateReferenceCache(ItemStateCacheFactory cacheFactory)
Creates a newItemStateReferenceCachethat uses aMLRUItemStateCacheinstance as internal cache.
-
ItemStateReferenceCache
public ItemStateReferenceCache(ItemStateCache cache)
Creates a newItemStateReferenceCachethat uses the specifiedItemStateCacheinstance as internal secondary cache.- Parameters:
cache- secondary cache implementing a custom eviction policy
-
-
Method Detail
-
isCached
public boolean isCached(ItemId id)
Returnstrueif this cache contains anItemStateobject with the specifiedid.- Specified by:
isCachedin interfaceItemStateCache- Parameters:
id- id ofItemStateobject whose presence should be tested.- Returns:
trueif there's a corresponding cache entry, otherwisefalse.
-
retrieve
public ItemState retrieve(ItemId id)
Returns theItemStateobject with the specifiedidif it is present ornullif no entry exists with thatid.- Specified by:
retrievein interfaceItemStateCache- Parameters:
id- the id of theItemStateobject to be returned.- Returns:
- the
ItemStateobject with the specifiedidor ornullif no entry exists with thatid
-
retrieveAll
public ItemState[] retrieveAll()
Returns all the cached item states.- Specified by:
retrieveAllin interfaceItemStateCache- Returns:
- newly allocated item state array
-
cache
public void cache(ItemState state)
Stores the specifiedItemStateobject in the map using itsItemIdas the key.- Specified by:
cachein interfaceItemStateCache- Parameters:
state- theItemStateobject to cache
-
evict
public void evict(ItemId id)
Removes theItemStateobject with the specified id from this cache if it is present.- Specified by:
evictin interfaceItemStateCache- Parameters:
id- the id of theItemStateobject which should be removed from this cache.
-
dispose
public void dispose()
Informs the cache that it is no longer in use.- Specified by:
disposein interfaceItemStateCache
-
evictAll
public void evictAll()
Clears all entries from this cache.- Specified by:
evictAllin interfaceItemStateCache
-
isEmpty
public boolean isEmpty()
Returnstrueif this cache contains no entries.- Specified by:
isEmptyin interfaceItemStateCache- Returns:
trueif this cache contains no entries.
-
-