Package org.apache.openjpa.util
Class CacheMap
java.lang.Object
org.apache.openjpa.util.CacheMap
- All Implemented Interfaces:
- Map
Fixed-size map that has ability to pin/unpin entries and move overflow to
 a backing soft map.
- Author:
- Patrick Linskey, Abe White
- 
Nested Class Summary
- 
Field SummaryFields
- 
Constructor SummaryConstructorsConstructorDescriptionCacheMap()Create a non-LRU (and therefore highly concurrent) cache map with a size of 1000.CacheMap(boolean lru) Create a cache map with a size of 1000.CacheMap(boolean lru, int max) Create a cache map with the given properties.CacheMap(boolean lru, int max, int size, float load) Deprecated.CacheMap(boolean lru, int max, int size, float load, int concurrencyLevel) Create a cache map with the given properties.
- 
Method SummaryModifier and TypeMethodDescriptionprotected voidcacheMapOverflowRemoved(Object key, Object value) Called fromSizedMap.overflowRemoved(java.lang.Object, java.lang.Object)in the cache map.voidclear()Removes pinned objects as well as unpinned ones.booleancontainsKey(Object key) booleancontainsValue(Object val) protected voidentryAdded(Object key, Object value) Invoked when an entry is added to the cache.protected voidentryRemoved(Object key, Object value, boolean expired) Invoked when a key-value pair is evicted from this data structure.entrySet()intThe maximum number of hard references to maintain, or -1 for no limit.The keys pinned into the map.intThe maximum number of soft references to maintain, or -1 for no limit.booleanisEmpty()booleanisLRU()Whether this cache map uses LRU eviction.keySet()booleanLocks the given key and its value into the map.protected ObjectPut the given entry into the given map.voidvoidvoidreadLock()Acquire read lock.voidRelease read lock.Ifkeyis pinned into the cache, the pin is cleared and the object is removed.protected ObjectRemove the given key from the given map.voidsetCacheSize(int size) The maximum number of hard references to maintain, or -1 for no limit.voidsetSoftReferenceSize(int size) The maximum number of soft references to maintain, or -1 for no limit.intsize()protected voidsoftMapOverflowRemoved(Object key, Object value) Called fromSizedMap.overflowRemoved(java.lang.Object, java.lang.Object)in the soft map.protected voidCalled when a value expires from the soft map.toString()booleanUndo a pinning.values()voidAcquire write lock.voidRelease write lock.Methods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Mapcompute, computeIfAbsent, computeIfPresent, equals, forEach, getOrDefault, hashCode, merge, putIfAbsent, remove, replace, replace, replaceAll
- 
Field Details- 
cacheMapThe map for non-expired and non-pinned references.
- 
softMapThe map for expired references.
- 
pinnedMapThe set of objects pinned into the cache.
 
- 
- 
Constructor Details- 
CacheMappublic CacheMap()Create a non-LRU (and therefore highly concurrent) cache map with a size of 1000.
- 
CacheMappublic CacheMap(boolean lru) Create a cache map with a size of 1000.- Parameters:
- lru- if true, create a LRU cache map otherwise a non-LRU map will be created.
 
- 
CacheMappublic CacheMap(boolean lru, int max) Create a cache map with the given properties.
- 
CacheMapDeprecated.useCacheMap(boolean, int, int, float, int)instead.
- 
CacheMappublic CacheMap(boolean lru, int max, int size, float load, int concurrencyLevel) Create a cache map with the given properties.- Since:
- 1.1.0
 
 
- 
- 
Method Details- 
cacheMapOverflowRemovedCalled fromSizedMap.overflowRemoved(java.lang.Object, java.lang.Object)in the cache map.
- 
softMapOverflowRemovedCalled fromSizedMap.overflowRemoved(java.lang.Object, java.lang.Object)in the soft map.
- 
softMapValueExpiredCalled when a value expires from the soft map.
- 
putPut the given entry into the given map. Allows subclasses to take additional actions.
- 
removeRemove the given key from the given map. Allows subclasses to take additional actions.
- 
readLockpublic void readLock()Acquire read lock.
- 
readUnlockpublic void readUnlock()Release read lock.
- 
writeLockpublic void writeLock()Acquire write lock.
- 
writeUnlockpublic void writeUnlock()Release write lock.
- 
isLRUpublic boolean isLRU()Whether this cache map uses LRU eviction.
- 
setCacheSizepublic void setCacheSize(int size) The maximum number of hard references to maintain, or -1 for no limit.
- 
getCacheSizepublic int getCacheSize()The maximum number of hard references to maintain, or -1 for no limit.
- 
setSoftReferenceSizepublic void setSoftReferenceSize(int size) The maximum number of soft references to maintain, or -1 for no limit.
- 
getSoftReferenceSizepublic int getSoftReferenceSize()The maximum number of soft references to maintain, or -1 for no limit.
- 
getPinnedKeysThe keys pinned into the map.
- 
pinLocks the given key and its value into the map. Objects pinned into the map are not counted towards the maximum cache size, and are never evicted implicitly. You may pin keys for which no value is in the map.- Returns:
- true if the givne key's value was pinned; false if no value for the given key is cached
 
- 
unpinUndo a pinning.
- 
entryRemovedInvoked when a key-value pair is evicted from this data structure. This is invoked withexpiredset totruewhen an object is dropped because of space requirements or through garbage collection of soft references. It is invoked withexpiredset tofalsewhen an object is explicitly removed via theremove(java.util.Map, java.lang.Object)orclear()methods. This may be invoked more than once for a given entry.- Parameters:
- value- may be null if the value was a soft reference that has been GCd
- Since:
- 0.2.5.0
 
- 
entryAddedInvoked when an entry is added to the cache. This may be invoked more than once for an entry.
- 
get
- 
put
- 
putAll
- 
putAll
- 
removeIfkeyis pinned into the cache, the pin is cleared and the object is removed.
- 
clearpublic void clear()Removes pinned objects as well as unpinned ones.
- 
sizepublic int size()
- 
isEmptypublic boolean isEmpty()
- 
containsKey- Specified by:
- containsKeyin interface- Map
 
- 
containsValue- Specified by:
- containsValuein interface- Map
 
- 
keySet
- 
values
- 
entrySet
- 
toString
 
- 
CacheMap(boolean, int, int, float, int)instead.