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
ItemStateReferenceCache
internally consists of 2 components:- an
ItemStateReferenceMap
serving as the primary (or main) cache; it holds weak references toItemState
instances. ThisItemStateCache
implementation 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
ItemStateCache
implementing 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 newItemStateReferenceCache
that uses the specifiedItemStateCache
instance as internal secondary cache.ItemStateReferenceCache(ItemStateCacheFactory cacheFactory)
Creates a newItemStateReferenceCache
that uses aMLRUItemStateCache
instance as internal cache.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
cache(ItemState state)
Stores the specifiedItemState
object in the map using itsItemId
as the key.void
dispose()
Informs the cache that it is no longer in use.void
evict(ItemId id)
Removes theItemState
object with the specified id from this cache if it is present.void
evictAll()
Clears all entries from this cache.boolean
isCached(ItemId id)
Returnstrue
if this cache contains anItemState
object with the specifiedid
.boolean
isEmpty()
Returnstrue
if this cache contains no entries.ItemState
retrieve(ItemId id)
Returns theItemState
object with the specifiedid
if it is present ornull
if no entry exists with thatid
.ItemState[]
retrieveAll()
Returns all the cached item states.
-
-
-
Constructor Detail
-
ItemStateReferenceCache
public ItemStateReferenceCache(ItemStateCacheFactory cacheFactory)
Creates a newItemStateReferenceCache
that uses aMLRUItemStateCache
instance as internal cache.
-
ItemStateReferenceCache
public ItemStateReferenceCache(ItemStateCache cache)
Creates a newItemStateReferenceCache
that uses the specifiedItemStateCache
instance as internal secondary cache.- Parameters:
cache
- secondary cache implementing a custom eviction policy
-
-
Method Detail
-
isCached
public boolean isCached(ItemId id)
Returnstrue
if this cache contains anItemState
object with the specifiedid
.- Specified by:
isCached
in interfaceItemStateCache
- Parameters:
id
- id ofItemState
object whose presence should be tested.- Returns:
true
if there's a corresponding cache entry, otherwisefalse
.
-
retrieve
public ItemState retrieve(ItemId id)
Returns theItemState
object with the specifiedid
if it is present ornull
if no entry exists with thatid
.- Specified by:
retrieve
in interfaceItemStateCache
- Parameters:
id
- the id of theItemState
object to be returned.- Returns:
- the
ItemState
object with the specifiedid
or ornull
if no entry exists with thatid
-
retrieveAll
public ItemState[] retrieveAll()
Returns all the cached item states.- Specified by:
retrieveAll
in interfaceItemStateCache
- Returns:
- newly allocated item state array
-
cache
public void cache(ItemState state)
Stores the specifiedItemState
object in the map using itsItemId
as the key.- Specified by:
cache
in interfaceItemStateCache
- Parameters:
state
- theItemState
object to cache
-
evict
public void evict(ItemId id)
Removes theItemState
object with the specified id from this cache if it is present.- Specified by:
evict
in interfaceItemStateCache
- Parameters:
id
- the id of theItemState
object which should be removed from this cache.
-
dispose
public void dispose()
Informs the cache that it is no longer in use.- Specified by:
dispose
in interfaceItemStateCache
-
evictAll
public void evictAll()
Clears all entries from this cache.- Specified by:
evictAll
in interfaceItemStateCache
-
isEmpty
public boolean isEmpty()
Returnstrue
if this cache contains no entries.- Specified by:
isEmpty
in interfaceItemStateCache
- Returns:
true
if this cache contains no entries.
-
-