Package org.apache.openjpa.datacache
Class ConcurrentDataCache
java.lang.Object
org.apache.openjpa.lib.util.concurrent.AbstractConcurrentEventManager
org.apache.openjpa.datacache.AbstractDataCache
org.apache.openjpa.datacache.ConcurrentDataCache
- All Implemented Interfaces:
Serializable
,DataCache
,RemoteCommitListener
,Configurable
,Clearable
,Closeable
,EventManager
- Direct Known Subclasses:
PartitionedDataCache
A
DataCache
implementation that is optimized for concurrent
access. When the cache fills up, values to remove from cache are chosen
randomly. Due to race conditions, it is possible that a get call might not
return a cached instance if that instance is being transferred between
internal datastructures.- Since:
- 0.4.0
- See Also:
-
Field Summary
Fields inherited from class org.apache.openjpa.datacache.AbstractDataCache
_evictOnBulkUpdate, _excludedTypes, _includedTypes, _stats, conf, log
Fields inherited from class org.apache.openjpa.lib.util.concurrent.AbstractConcurrentEventManager
_listeners
Fields inherited from interface org.apache.openjpa.datacache.DataCache
NAME_DEFAULT
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
Clear the cache.Returns the underlyingCacheMap
that this cache is using.int
Returns the maximum number of unpinned objects to keep hard references to.protected DataCachePCData
getInternal
(Object key) Return the object for the given oid.boolean
getLru()
int
Returns the maximum number of unpinned objects to keep soft references to.void
Initialize any resources associated with the givenDataCacheManager
.protected CacheMap
Return the map to use as an internal cache; entry expirations must invokeAbstractDataCache.keyRemoved(java.lang.Object, boolean)
.protected boolean
pinInternal
(Object key) Pin an object to the cache.protected DataCachePCData
putInternal
(Object key, DataCachePCData pc) Add the given object to the cache, returning the old object under the given oid.protected boolean
Returntrue
if updates to data already in the cache (either inAbstractDataCache.commit(java.util.Collection<org.apache.openjpa.datacache.DataCachePCData>, java.util.Collection<org.apache.openjpa.datacache.DataCachePCData>, java.util.Collection<org.apache.openjpa.datacache.DataCachePCData>, java.util.Collection<java.lang.Object>)
or theAbstractDataCache.update(org.apache.openjpa.datacache.DataCachePCData)
) should be put back into the cache.protected void
removeAllInternal
(Class<?> cls, boolean subs) Evict objects in cache by class.protected DataCachePCData
removeInternal
(Object key) Remove the object under the given oid from the cache.void
setCacheSize
(int size) Sets the maximum number of unpinned objects to keep hard references to.void
setLru
(boolean l) void
setSoftReferenceSize
(int size) Sets the maximum number of unpinned objects to keep soft references to.void
Unpin all oids associaed with the given type from the cache.protected boolean
unpinInternal
(Object key) Unpin an object from the cache.void
Obtain a write lock on the cache.void
Release the write lock on the cache.Methods inherited from class org.apache.openjpa.datacache.AbstractDataCache
addExpirationListener, afterCommit, clear, close, close, commit, contains, containsAll, endConfiguration, fireEvent, get, getAll, getEnableStatistics, getEvictionSchedule, getEvictOnBulkUpdate, getExcludedTypes, getName, getPartition, getPartitionNames, getStatistics, getTypes, isClosed, isPartitioned, keyRemoved, pin, pinAll, pinAll, put, putAllInternal, remove, removeAll, removeAll, removeAllInternal, removeAllTypeNamesInternal, removeExpirationListener, selectCache, setConfiguration, setEnableStatistics, setEvictionSchedule, setEvictOnBulkUpdate, setExcludedTypes, setExcludedTypes, setName, setTypes, setTypes, startConfiguration, toString, unpin, unpinAll, update
Methods inherited from class org.apache.openjpa.lib.util.concurrent.AbstractConcurrentEventManager
addListener, fireEvent, getListeners, hasListener, hasListeners, isFailFast, newListenerCollection, removeListener, setFailFast
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.apache.openjpa.event.RemoteCommitListener
afterCommit, close
-
Field Details
-
_lru
protected boolean _lru
-
-
Constructor Details
-
ConcurrentDataCache
public ConcurrentDataCache()
-
-
Method Details
-
getCacheMap
Returns the underlyingCacheMap
that this cache is using. This is not an unmodifiable view on the map, so care should be taken with this reference. Implementations should probably not modify the contents of the cache, but should only use this reference to obtain cache metrics. -
setCacheSize
public void setCacheSize(int size) Sets the maximum number of unpinned objects to keep hard references to. If the map contains more unpinned objects thansize
, then this method will result in the cache flushing old values. -
getCacheSize
public int getCacheSize()Returns the maximum number of unpinned objects to keep hard references to. -
setSoftReferenceSize
public void setSoftReferenceSize(int size) Sets the maximum number of unpinned objects to keep soft references to. If the map contains more soft references thansize
, then this method will result in the cache flushing values. -
getSoftReferenceSize
public int getSoftReferenceSize()Returns the maximum number of unpinned objects to keep soft references to. Defaults to-1
. -
initialize
Description copied from interface:DataCache
Initialize any resources associated with the givenDataCacheManager
.- Specified by:
initialize
in interfaceDataCache
- Overrides:
initialize
in classAbstractDataCache
-
unpinAll
Description copied from interface:DataCache
Unpin all oids associaed with the given type from the cache.- Specified by:
unpinAll
in interfaceDataCache
- Overrides:
unpinAll
in classAbstractDataCache
subs
- Whether to include subclasses.
-
writeLock
public void writeLock()Description copied from interface:DataCache
Obtain a write lock on the cache. -
writeUnlock
public void writeUnlock()Description copied from interface:DataCache
Release the write lock on the cache.- Specified by:
writeUnlock
in interfaceDataCache
-
newCacheMap
Return the map to use as an internal cache; entry expirations must invokeAbstractDataCache.keyRemoved(java.lang.Object, boolean)
. -
getInternal
Description copied from class:AbstractDataCache
Return the object for the given oid.- Specified by:
getInternal
in classAbstractDataCache
-
putInternal
Description copied from class:AbstractDataCache
Add the given object to the cache, returning the old object under the given oid.- Specified by:
putInternal
in classAbstractDataCache
-
removeInternal
Description copied from class:AbstractDataCache
Remove the object under the given oid from the cache.- Specified by:
removeInternal
in classAbstractDataCache
-
removeAllInternal
Description copied from class:AbstractDataCache
Evict objects in cache by class.- Specified by:
removeAllInternal
in classAbstractDataCache
-
clearInternal
protected void clearInternal()Description copied from class:AbstractDataCache
Clear the cache.- Specified by:
clearInternal
in classAbstractDataCache
-
pinInternal
Description copied from class:AbstractDataCache
Pin an object to the cache.- Specified by:
pinInternal
in classAbstractDataCache
-
unpinInternal
Description copied from class:AbstractDataCache
Unpin an object from the cache.- Specified by:
unpinInternal
in classAbstractDataCache
-
recacheUpdates
protected boolean recacheUpdates()Description copied from class:AbstractDataCache
Returntrue
if updates to data already in the cache (either inAbstractDataCache.commit(java.util.Collection<org.apache.openjpa.datacache.DataCachePCData>, java.util.Collection<org.apache.openjpa.datacache.DataCachePCData>, java.util.Collection<org.apache.openjpa.datacache.DataCachePCData>, java.util.Collection<java.lang.Object>)
or theAbstractDataCache.update(org.apache.openjpa.datacache.DataCachePCData)
) should be put back into the cache. Returns false by default.- Overrides:
recacheUpdates
in classAbstractDataCache
-
setLru
public void setLru(boolean l) -
getLru
public boolean getLru()
-