Class DefaultCacheRegion
- java.lang.Object
-
- de.hybris.platform.regioncache.region.impl.DefaultCacheRegion
-
- All Implemented Interfaces:
CacheRegion
public class DefaultCacheRegion extends java.lang.Object implements CacheRegion
Default cache region implementation.
For the synchronization it uses ReentrantReadWriteLock one for whole cache map. It is really inefficient then.
-
-
Field Summary
Fields Modifier and Type Field Description protected CacheMapcacheMapprotected booleanexclusiveComputationprotected java.lang.String[]handledTypesprotected CacheLifecycleCallbacklifecycleCallbackprotected java.lang.Stringnameprotected java.util.concurrent.locks.ReentrantReadWriteLocksharedLockprotected CacheStatisticsstatsprotected booleanstatsEnabled
-
Constructor Summary
Constructors Constructor Description DefaultCacheRegion(java.lang.String name)DefaultCacheRegion(java.lang.String name, boolean exclusiveComputation, boolean statsEnabled)DefaultCacheRegion(java.lang.String name, int maxEntries)DefaultCacheRegion(java.lang.String name, int maxEntries, boolean exclusiveComputation, boolean statsEnabled)DefaultCacheRegion(java.lang.String name, int maxEntries, boolean exclusiveComputation, java.lang.String evictionPolicy, boolean statsEnabled)Deprecated.since 1811DefaultCacheRegion(java.lang.String name, CacheMap cacheMap, CacheStatistics stats, java.lang.String[] handledTypes)DefaultCacheRegion(java.lang.String name, CacheMap cacheMap, CacheStatistics stats, java.lang.String[] handledTypes, boolean exclusiveComputation, boolean statsEnabled)DefaultCacheRegion(java.lang.String name, CacheMap cacheMap, java.lang.String[] handledTypes)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclearCache()Removes all elements from cache.booleancontainsKey(CacheKey key)Checks if key is in the cache map.booleanequals(java.lang.Object obj)java.lang.Objectget(CacheKey key)Gets value from the cache.java.util.Collection<CacheKey>getAllKeys()Returns all keys currently stored in this region.CacheMapgetCacheMap()longgetCacheMaxEntries()Gets number of cache entries above which invalidation occurs.CacheStatisticsgetCacheRegionStatistics()Gets statistics for current region.java.lang.String[]getHandledTypes()Gets types which can be stored in the region.longgetMaxReachedSize()Returns number of elements currently in the cachejava.lang.StringgetName()Gets region name.java.lang.ObjectgetWithLoader(CacheKey key, CacheValueLoader loader)Gets value from cache.inthashCode()voidinit()java.lang.Objectinvalidate(CacheKey key, boolean fireEventsEvenIfNotRemoved)Invalidates (removes) value from cache map.booleanisStatsEnabled()voidregisterLifecycleCallback(CacheLifecycleCallback callback)This callback shall be called when eviction occurs.java.lang.Objectremove(CacheKey key, boolean fireEvents)Removes value stored on the key specified.voidsetCacheMap(CacheMap cacheMap)voidsetHandledTypes(java.lang.String[] handledTypes)voidsetStatsEnabled(boolean enabled)java.lang.StringtoString()
-
-
-
Field Detail
-
cacheMap
protected CacheMap cacheMap
-
handledTypes
protected java.lang.String[] handledTypes
-
lifecycleCallback
protected CacheLifecycleCallback lifecycleCallback
-
name
protected final java.lang.String name
-
stats
protected final CacheStatistics stats
-
sharedLock
protected final java.util.concurrent.locks.ReentrantReadWriteLock sharedLock
-
statsEnabled
protected volatile boolean statsEnabled
-
exclusiveComputation
protected final boolean exclusiveComputation
-
-
Constructor Detail
-
DefaultCacheRegion
public DefaultCacheRegion(java.lang.String name)
-
DefaultCacheRegion
public DefaultCacheRegion(java.lang.String name, CacheMap cacheMap, java.lang.String[] handledTypes)
-
DefaultCacheRegion
public DefaultCacheRegion(java.lang.String name, boolean exclusiveComputation, boolean statsEnabled)
-
DefaultCacheRegion
public DefaultCacheRegion(java.lang.String name, CacheMap cacheMap, CacheStatistics stats, java.lang.String[] handledTypes)
-
DefaultCacheRegion
public DefaultCacheRegion(java.lang.String name, CacheMap cacheMap, CacheStatistics stats, java.lang.String[] handledTypes, boolean exclusiveComputation, boolean statsEnabled)
-
DefaultCacheRegion
public DefaultCacheRegion(java.lang.String name, int maxEntries, boolean exclusiveComputation, boolean statsEnabled)
-
DefaultCacheRegion
@Deprecated public DefaultCacheRegion(java.lang.String name, int maxEntries, boolean exclusiveComputation, java.lang.String evictionPolicy, boolean statsEnabled)Deprecated.since 1811- Parameters:
evictionPolicy-
-
DefaultCacheRegion
public DefaultCacheRegion(java.lang.String name, int maxEntries)
-
-
Method Detail
-
init
@PostConstruct public void init()
-
get
public java.lang.Object get(CacheKey key)
Description copied from interface:CacheRegionGets value from the cache. If value is absent returns null. Must be thread safe.- Specified by:
getin interfaceCacheRegion
-
getMaxReachedSize
public long getMaxReachedSize()
Description copied from interface:CacheRegionReturns number of elements currently in the cache- Specified by:
getMaxReachedSizein interfaceCacheRegion
-
getWithLoader
public java.lang.Object getWithLoader(CacheKey key, CacheValueLoader loader) throws CacheValueLoadException
Description copied from interface:CacheRegionGets value from cache. Invokes loader if necessary. Must be thread safe.- Specified by:
getWithLoaderin interfaceCacheRegion- Throws:
CacheValueLoadException
-
invalidate
public java.lang.Object invalidate(CacheKey key, boolean fireEventsEvenIfNotRemoved)
Description copied from interface:CacheRegionInvalidates (removes) value from cache map. Must be thread safe.- Specified by:
invalidatein interfaceCacheRegion- Returns:
- an object invalidated from cache.
-
getName
public java.lang.String getName()
Description copied from interface:CacheRegionGets region name. Needed to resolve proper cache region.- Specified by:
getNamein interfaceCacheRegion
-
getHandledTypes
public java.lang.String[] getHandledTypes()
Description copied from interface:CacheRegionGets types which can be stored in the region. Needed to resolve proper cache region.
Special type names are defined inRegionType.- Specified by:
getHandledTypesin interfaceCacheRegion
-
setHandledTypes
public void setHandledTypes(java.lang.String[] handledTypes)
-
getCacheMap
public CacheMap getCacheMap()
- Returns:
- the cacheMap
-
setCacheMap
public void setCacheMap(CacheMap cacheMap)
- Parameters:
cacheMap- the cacheMap to set
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
getCacheRegionStatistics
public CacheStatistics getCacheRegionStatistics()
Description copied from interface:CacheRegionGets statistics for current region.- Specified by:
getCacheRegionStatisticsin interfaceCacheRegion
-
getCacheMaxEntries
public long getCacheMaxEntries()
Description copied from interface:CacheRegionGets number of cache entries above which invalidation occurs.- Specified by:
getCacheMaxEntriesin interfaceCacheRegion
-
clearCache
public void clearCache()
Description copied from interface:CacheRegionRemoves all elements from cache.- Specified by:
clearCachein interfaceCacheRegion
-
registerLifecycleCallback
public void registerLifecycleCallback(CacheLifecycleCallback callback)
Description copied from interface:CacheRegionThis callback shall be called when eviction occurs.- Specified by:
registerLifecycleCallbackin interfaceCacheRegion
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
getAllKeys
public java.util.Collection<CacheKey> getAllKeys()
Description copied from interface:CacheRegionReturns all keys currently stored in this region.- Specified by:
getAllKeysin interfaceCacheRegion
-
remove
public java.lang.Object remove(CacheKey key, boolean fireEvents)
Description copied from interface:CacheRegionRemoves value stored on the key specified. This method does not update statistics. Returns value removed or null.- Specified by:
removein interfaceCacheRegion
-
containsKey
public boolean containsKey(CacheKey key)
Description copied from interface:CacheRegionChecks if key is in the cache map.- Specified by:
containsKeyin interfaceCacheRegion
-
setStatsEnabled
public void setStatsEnabled(boolean enabled)
- Specified by:
setStatsEnabledin interfaceCacheRegion
-
isStatsEnabled
public boolean isStatsEnabled()
- Specified by:
isStatsEnabledin interfaceCacheRegion
-
-