public class ConcurrentDataCache extends AbstractDataCache implements RemoteCommitListener
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.Modifier and Type | Field and Description |
---|---|
protected boolean |
_lru |
_evictOnBulkUpdate, _excludedTypes, _includedTypes, _stats, conf, log
_listeners
NAME_DEFAULT
Constructor and Description |
---|
ConcurrentDataCache() |
Modifier and Type | Method and Description |
---|---|
protected void |
clearInternal()
Clear the cache.
|
CacheMap |
getCacheMap()
Returns the underlying
CacheMap that this cache is using. |
int |
getCacheSize()
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 |
getSoftReferenceSize()
Returns the maximum number of unpinned objects to keep soft
references to.
|
void |
initialize(DataCacheManager mgr)
Initialize any resources associated with the given
DataCacheManager . |
protected CacheMap |
newCacheMap()
Return the map to use as an internal cache; entry expirations must
invoke
AbstractDataCache.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 |
recacheUpdates()
Return
true if updates to data already in the
cache (either in AbstractDataCache.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 the AbstractDataCache.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 |
unpinAll(Class<?> cls,
boolean subs)
Unpin all oids associaed with the given type from the cache.
|
protected boolean |
unpinInternal(Object key)
Unpin an object from the cache.
|
void |
writeLock()
Obtain a write lock on the cache.
|
void |
writeUnlock()
Release the write lock on the cache.
|
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
addListener, fireEvent, getListeners, hasListener, hasListeners, isFailFast, newListenerCollection, removeListener, setFailFast
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
afterCommit, close
public CacheMap getCacheMap()
CacheMap
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.public void setCacheSize(int size)
size
, then this method will result in the cache
flushing old values.public int getCacheSize()
public void setSoftReferenceSize(int size)
size
, then this method will result in the cache
flushing values.public int getSoftReferenceSize()
-1
.public void initialize(DataCacheManager mgr)
DataCache
DataCacheManager
.initialize
in interface DataCache
initialize
in class AbstractDataCache
public void unpinAll(Class<?> cls, boolean subs)
DataCache
unpinAll
in interface DataCache
unpinAll
in class AbstractDataCache
subs
- Whether to include subclasses.public void writeLock()
DataCache
public void writeUnlock()
DataCache
writeUnlock
in interface DataCache
protected CacheMap newCacheMap()
AbstractDataCache.keyRemoved(java.lang.Object, boolean)
.protected DataCachePCData getInternal(Object key)
AbstractDataCache
getInternal
in class AbstractDataCache
protected DataCachePCData putInternal(Object key, DataCachePCData pc)
AbstractDataCache
putInternal
in class AbstractDataCache
protected DataCachePCData removeInternal(Object key)
AbstractDataCache
removeInternal
in class AbstractDataCache
protected void removeAllInternal(Class<?> cls, boolean subs)
AbstractDataCache
removeAllInternal
in class AbstractDataCache
protected void clearInternal()
AbstractDataCache
clearInternal
in class AbstractDataCache
protected boolean pinInternal(Object key)
AbstractDataCache
pinInternal
in class AbstractDataCache
protected boolean unpinInternal(Object key)
AbstractDataCache
unpinInternal
in class AbstractDataCache
protected boolean recacheUpdates()
AbstractDataCache
true
if updates to data already in the
cache (either in AbstractDataCache.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 the AbstractDataCache.update(org.apache.openjpa.datacache.DataCachePCData)
)
should be put back into the cache. Returns false by default.recacheUpdates
in class AbstractDataCache
public void setLru(boolean l)
public boolean getLru()
Copyright © 2006–2019 Apache Software Foundation. All rights reserved.