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
public final class DefaultCache extends StaticCache implements Cache
-
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.StringtenantId-
Fields 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
Constructors Constructor Description DefaultCache(Tenant tenant, int maxCacheSize)Creates a new cache.DefaultCache(Tenant tenant, int maxCacheSize, boolean forceExclComp)Creates a new cache.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()voidclearStats()Clears the collected cache statistics.voiddestroy()Method called by tennant to free resources before object is finalizedvoidenableStats(boolean enabled)Enables or disables the cache statistics.AbstractCacheUnitgetAbstractCacheUnit(java.lang.String firstKeyElement, java.lang.String secondKeyElement, java.lang.String thirdKeyElement, PK fourthKeyElement)for performance optimizations: get a existing cache unit; the key of the cache unit must consist of exactly three elementslonggetAddCount()longgetGetCount()intgetMaxAllowedSize()The upper limit for the cache.intgetMaxReachedSize()the maximum reached number of entries since creation of the cache.longgetMissCount()AbstractCacheUnitgetOrAddUnit(AbstractCacheUnit unit)gets value stored in the cache or loads it.
Throws exception wrapped into RuntimeExceptionAbstractCacheUnitgetOrAddUnitInternal(AbstractCacheUnit unit, java.util.concurrent.locks.ReadWriteLock rwLock)longgetRemoveCount()intgetSize()the current size of the internal cache (in 'entries')java.util.SetgetStatistics(int upperBound, int lowerBound)Returns asSetthe collected cache statistics.TenantgetTenant()get the tenant this cache is created for.java.lang.StringgetTenantId()AbstractCacheUnitgetUnit(AbstractCacheUnit unit)CacheMapinternalCreateMapInstance(int max)static CacheMapinternalCreateMapInstanceStatic(Tenant tenant, int max)voidinvalidate(java.lang.Object[] key, int invalidationType)execute invalidation (not delayed to transaction end)booleanisForceExclusiveComputation()TellsAbstractCacheUnitwhether value computation should be exclusive (synchronized) or not.static booleanisMultiPathKey(java.lang.Object[] key)Tells whether the given key array actually contains multiple keys.booleanisStatsEmpty()Returnstrueif no cache statistics are collected.static java.lang.StringkeyToString(java.lang.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.booleanstatsEnabled()Returnstrueif the statistics for the cache are enabled.static java.util.List<java.lang.Object[]>toSingleKey(java.lang.Object[] key)Transforms a given key into one or more single keys.java.lang.StringtoString()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, getStaticCacheContent
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface de.hybris.platform.cache.Cache
getRequestCacheContent, getRequestCacheContentIfExists, getStaticCacheContent
-
-
-
-
Constructor Detail
-
DefaultCache
public DefaultCache(Tenant tenant, int maxCacheSize)
Creates a new cache.- Parameters:
tenant- the cache ownermaxCacheSize- the max cache size
-
DefaultCache
public DefaultCache(Tenant tenant, int maxCacheSize, boolean forceExclComp)
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 Detail
-
internalCreateMapInstance
public CacheMap internalCreateMapInstance(int max)
-
internalCreateMapInstanceStatic
public static CacheMap internalCreateMapInstanceStatic(Tenant tenant, int max)
-
destroy
public void destroy()
Description copied from interface:CacheMethod called by tennant to free resources before object is finalized
-
getTenant
public Tenant 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
public java.lang.String getTenantId()
- Specified by:
getTenantIdin interfaceCache
-
toString
public java.lang.String toString()
prints out some more or less useful information about this cache instance (like the maximum allowed size)- Overrides:
toStringin classjava.lang.Object
-
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
-
isMultiPathKey
public static boolean isMultiPathKey(java.lang.Object[] key)
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(Object[])
-
toSingleKey
public static java.util.List<java.lang.Object[]> toSingleKey(java.lang.Object[] key)
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:
isMultiPathKey(Object[])
-
removeUnit
public void removeUnit(AbstractCacheUnit unit)
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
public AbstractCacheUnit getUnit(AbstractCacheUnit unit)
-
getOrAddUnit
public AbstractCacheUnit getOrAddUnit(AbstractCacheUnit unit)
Description copied from interface:Cachegets value stored in the cache or loads it.
Throws exception wrapped into RuntimeException- Specified by:
getOrAddUnitin interfaceCache
-
getOrAddUnitInternal
public AbstractCacheUnit getOrAddUnitInternal(AbstractCacheUnit unit, java.util.concurrent.locks.ReadWriteLock rwLock)
-
invalidate
public void invalidate(java.lang.Object[] key, int invalidationType)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(java.lang.String firstKeyElement, java.lang.String secondKeyElement, java.lang.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
public java.util.Set getStatistics(int upperBound, int lowerBound)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
public static java.lang.String keyToString(java.lang.Object[] key)
-
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
-
-