Package de.hybris.platform.cache.impl
Class DefaultCache
java.lang.Object
de.hybris.platform.cache.impl.StaticCache
de.hybris.platform.cache.impl.DefaultCache
- All Implemented Interfaces:
Cache,InvalidationTarget
-
Field Summary
FieldsFields inherited from interface de.hybris.platform.cache.Cache
CACHEKEY_C2LMANAGER, CACHEKEY_CUSTOM, CACHEKEY_ENTITY, CACHEKEY_ENTITYISALIVE, CACHEKEY_FIND, CACHEKEY_FLEXSEARCH, CACHEKEY_HJMP, CACHEKEY_JALOITEMCACHE, CACHEKEY_JALOITEMDATA, CACHEKEY_JALOTYPE, CONFIG_CACHE_MAIN, CONFIG_CACHE_SHARED, CONFIG_CONCURRENCY_LEVEL, CONFIG_EVICTION_POLICY, CONFIG_FORCE_EXCLUSIVE_CALCULATION, DEFAULT_CACHE_MAIN, DEFAULT_CACHE_SHARED, LIMIT_CACHE_MAIN -
Constructor Summary
ConstructorsConstructorDescriptionDefaultCache(Tenant tenant, int maxCacheSize) Creates a new cache.DefaultCache(Tenant tenant, int maxCacheSize, boolean forceExclComp) Creates a new cache. -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()voidClears the collected cache statistics.voiddestroy()Method called by tennant to free resources before object is finalizedvoidenableStats(boolean enabled) Enables or disables the cache statistics.getAbstractCacheUnit(String firstKeyElement, String secondKeyElement, String thirdKeyElement, PK fourthKeyElement) for performance optimizations: get a existing cache unit; the key of the cache unit must consist of exactly three elementslonglongintThe upper limit for the cache.intthe maximum reached number of entries since creation of the cache.longgets value stored in the cache or loads it.
Throws exception wrapped into RuntimeExceptiongetOrAddUnitInternal(AbstractCacheUnit unit, ReadWriteLock rwLock) longintgetSize()the current size of the internal cache (in 'entries')getStatistics(int upperBound, int lowerBound) Returns asSetthe collected cache statistics.get the tenant this cache is created for.getUnit(AbstractCacheUnit unit) internalCreateMapInstance(int max) static CacheMapinternalCreateMapInstanceStatic(Tenant tenant, int max) voidinvalidate(Object[] key, int invalidationType) execute invalidation (not delayed to transaction end)booleanTellsAbstractCacheUnitwhether value computation should be exclusive (synchronized) or not.static booleanisMultiPathKey(Object[] key) Tells whether the given key array actually contains multiple keys.booleanReturnstrueif no cache statistics are collected.static StringkeyToString(Object[] key) voidremoveUnit(AbstractCacheUnit unit) Removes a cache unit from this cache.voidsetEnabled(boolean enabled) enables/disables the cache.voidsetStatsEnabled(boolean enabled) Enables or disables the cache statistics.booleanReturnstrueif the statistics for the cache are enabled.toSingleKey(Object[] key) Transforms a given key into one or more single keys.toString()prints out some more or less useful information about this cache instance (like the maximum allowed size)Methods inherited from class de.hybris.platform.cache.impl.StaticCache
clearRequestCache, clearStaticCache, getRequestCacheContent, getRequestCacheContentIfExists, getRequestCacheMap, getStaticCacheContentMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface de.hybris.platform.cache.Cache
getRequestCacheContent, getRequestCacheContentIfExists, getStaticCacheContent
-
Field Details
-
tenantId
-
-
Constructor Details
-
DefaultCache
Creates a new cache.- Parameters:
tenant- the cache ownermaxCacheSize- the max cache size
-
DefaultCache
Creates a new cache.- Parameters:
tenant- the cache ownermaxCacheSize- the max cache sizeforceExclComp- allows to specify CONFIG_FORCE_EXCLUSIVE_CALCULATION manually instead of reading it from tenant configuration
-
-
Method Details
-
internalCreateMapInstance
-
internalCreateMapInstanceStatic
-
destroy
public void destroy()Description copied from interface:CacheMethod called by tennant to free resources before object is finalized -
getTenant
get the tenant this cache is created for. The hybris 'internal' cache (Tenant.getCache()always has a tenant, but it is possible to create your own Cache without assigning to a tenant. -
getTenantId
- Specified by:
getTenantIdin interfaceCache
-
toString
prints out some more or less useful information about this cache instance (like the maximum allowed size) -
setEnabled
public void setEnabled(boolean enabled) Description copied from interface:Cacheenables/disables the cache.- Specified by:
setEnabledin interfaceCache- Parameters:
enabled-truefor enabling the cache,falseotherwise.
-
getSize
public int getSize()the current size of the internal cache (in 'entries') -
getMaxAllowedSize
public int getMaxAllowedSize()The upper limit for the cache. this normally equals the setting 'cache.main' and is the number of cache entries that are allowed until the cache mechanism will remove the least recently used entries before adding new ones.- Specified by:
getMaxAllowedSizein interfaceCache- Returns:
- the max allowed size
-
getMaxReachedSize
public int getMaxReachedSize()the maximum reached number of entries since creation of the cache. this is only reseted if Cache#clearCache() is called.- Specified by:
getMaxReachedSizein interfaceCache
-
clear
public void clear() -
isMultiPathKey
Tells whether the given key array actually contains multiple keys.Examples
Multi-key : [ [ foo, bar, 1 ] [ x, y, z ] ] Single key : [ foo, bar, 1 ]
- See Also:
-
toSingleKey
Transforms a given key into one or more single keys. If the given key just contains a single key a singleton list it is being returned. If it consists of multiple keys a list of these keys is returned.- See Also:
-
removeUnit
Removes a cache unit from this cache.- Specified by:
removeUnitin interfaceCache- Parameters:
unit- the unit to be removed. note that the same of any unit with the same key is removed.
-
getUnit
-
getOrAddUnit
Description copied from interface:Cachegets value stored in the cache or loads it.
Throws exception wrapped into RuntimeException- Specified by:
getOrAddUnitin interfaceCache
-
getOrAddUnitInternal
-
invalidate
execute invalidation (not delayed to transaction end)- Specified by:
invalidatein interfaceCache- Specified by:
invalidatein interfaceInvalidationTarget- Parameters:
key- may be an incomplete key, for group invalidation
-
getAbstractCacheUnit
public AbstractCacheUnit getAbstractCacheUnit(String firstKeyElement, String secondKeyElement, String thirdKeyElement, PK fourthKeyElement) for performance optimizations: get a existing cache unit; the key of the cache unit must consist of exactly three elements- Specified by:
getAbstractCacheUnitin interfaceCache
-
getAddCount
public long getAddCount()- Specified by:
getAddCountin interfaceCache- Returns:
- how many entities where added to the cache since creation of the cache. This is reseted by calling
clear()orclearStats().
-
getRemoveCount
public long getRemoveCount()- Specified by:
getRemoveCountin interfaceCache- Returns:
- how many entities where removed from the cache since creation of the cache. This is reseted by calling
clear()orclearStats().
-
getGetCount
public long getGetCount()- Specified by:
getGetCountin interfaceCache- Returns:
- how many entities where requested from the cache since creation of the cache. This is reseted by calling
clear()orclearStats().
-
getMissCount
public long getMissCount()- Specified by:
getMissCountin interfaceCache- Returns:
- how many entities where requested from the cache but wasn't in the cache (yet) since creation of the
cache. This is reseted by calling
clear()orclearStats().
-
statsEnabled
public boolean statsEnabled()Returnstrueif the statistics for the cache are enabled. This can be modified with the methodenableStats(boolean). Collecting the statistics is very memory intensive - useclearStats()frequently.- Specified by:
statsEnabledin interfaceCache- Returns:
falseotherwise.
-
enableStats
public void enableStats(boolean enabled) Enables or disables the cache statistics.- Specified by:
enableStatsin interfaceCache- Parameters:
enabled-truefor enabling the statistics
-
clearStats
public void clearStats()Clears the collected cache statistics.- Specified by:
clearStatsin interfaceCache
-
isStatsEmpty
public boolean isStatsEmpty()Returnstrueif no cache statistics are collected. (addToStatistics(Object[], boolean)was not called yet)- Specified by:
isStatsEmptyin interfaceCache- Returns:
falseotherwise
-
isForceExclusiveComputation
public boolean isForceExclusiveComputation()TellsAbstractCacheUnitwhether value computation should be exclusive (synchronized) or not.- Specified by:
isForceExclusiveComputationin interfaceCache
-
getStatistics
Returns asSetthe collected cache statistics. Each set entry is aCacheStatisticsEntry. With the parametersupperBoundandlowerBounda reduced Set will be returned.CacheStatisticsEntry.getFactor()must be betweenupperBoundandlowerBound.- Specified by:
getStatisticsin interfaceCache- Parameters:
upperBound- the upper bound for the returned set. Each entry factor is equal or less.lowerBound- the lower bound the the returned set. Each entry factor is greater or equal.- Returns:
- a Set with
CacheStatisticsEntry.
-
keyToString
-
setStatsEnabled
public void setStatsEnabled(boolean enabled) Description copied from interface:CacheEnables or disables the cache statistics.- Specified by:
setStatsEnabledin interfaceCache- Parameters:
enabled-truefor enabling the statistics
-