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
FieldsFields inherited from class org.apache.openjpa.datacache.AbstractDataCache
_evictOnBulkUpdate, _excludedTypes, _includedTypes, _stats, conf, logFields inherited from class org.apache.openjpa.lib.util.concurrent.AbstractConcurrentEventManager
_listenersFields inherited from interface org.apache.openjpa.datacache.DataCache
NAME_DEFAULT -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidClear the cache.Returns the underlyingCacheMapthat this cache is using.intReturns the maximum number of unpinned objects to keep hard references to.protected DataCachePCDatagetInternal(Object key) Return the object for the given oid.booleangetLru()intReturns the maximum number of unpinned objects to keep soft references to.voidInitialize any resources associated with the givenDataCacheManager.protected CacheMapReturn the map to use as an internal cache; entry expirations must invokeAbstractDataCache.keyRemoved(java.lang.Object, boolean).protected booleanpinInternal(Object key) Pin an object to the cache.protected DataCachePCDataputInternal(Object key, DataCachePCData pc) Add the given object to the cache, returning the old object under the given oid.protected booleanReturntrueif 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 voidremoveAllInternal(Class<?> cls, boolean subs) Evict objects in cache by class.protected DataCachePCDataremoveInternal(Object key) Remove the object under the given oid from the cache.voidsetCacheSize(int size) Sets the maximum number of unpinned objects to keep hard references to.voidsetLru(boolean l) voidsetSoftReferenceSize(int size) Sets the maximum number of unpinned objects to keep soft references to.voidUnpin all oids associaed with the given type from the cache.protected booleanunpinInternal(Object key) Unpin an object from the cache.voidObtain a write lock on the cache.voidRelease 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, updateMethods inherited from class org.apache.openjpa.lib.util.concurrent.AbstractConcurrentEventManager
addListener, fireEvent, getListeners, hasListener, hasListeners, isFailFast, newListenerCollection, removeListener, setFailFastMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods 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 underlyingCacheMapthat 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:DataCacheInitialize any resources associated with the givenDataCacheManager.- Specified by:
initializein interfaceDataCache- Overrides:
initializein classAbstractDataCache
-
unpinAll
Description copied from interface:DataCacheUnpin all oids associaed with the given type from the cache.- Specified by:
unpinAllin interfaceDataCache- Overrides:
unpinAllin classAbstractDataCachesubs- Whether to include subclasses.
-
writeLock
public void writeLock()Description copied from interface:DataCacheObtain a write lock on the cache. -
writeUnlock
public void writeUnlock()Description copied from interface:DataCacheRelease the write lock on the cache.- Specified by:
writeUnlockin 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:AbstractDataCacheReturn the object for the given oid.- Specified by:
getInternalin classAbstractDataCache
-
putInternal
Description copied from class:AbstractDataCacheAdd the given object to the cache, returning the old object under the given oid.- Specified by:
putInternalin classAbstractDataCache
-
removeInternal
Description copied from class:AbstractDataCacheRemove the object under the given oid from the cache.- Specified by:
removeInternalin classAbstractDataCache
-
removeAllInternal
Description copied from class:AbstractDataCacheEvict objects in cache by class.- Specified by:
removeAllInternalin classAbstractDataCache
-
clearInternal
protected void clearInternal()Description copied from class:AbstractDataCacheClear the cache.- Specified by:
clearInternalin classAbstractDataCache
-
pinInternal
Description copied from class:AbstractDataCachePin an object to the cache.- Specified by:
pinInternalin classAbstractDataCache
-
unpinInternal
Description copied from class:AbstractDataCacheUnpin an object from the cache.- Specified by:
unpinInternalin classAbstractDataCache
-
recacheUpdates
protected boolean recacheUpdates()Description copied from class:AbstractDataCacheReturntrueif 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:
recacheUpdatesin classAbstractDataCache
-
setLru
public void setLru(boolean l) -
getLru
public boolean getLru()
-