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 Details

    • tenantId

      protected final String tenantId
  • Constructor Details

    • DefaultCache

      public DefaultCache(Tenant tenant, int maxCacheSize)
      Creates a new cache.
      Parameters:
      tenant - the cache owner
      maxCacheSize - the max cache size
    • DefaultCache

      public DefaultCache(Tenant tenant, int maxCacheSize, boolean forceExclComp)
      Creates a new cache.
      Parameters:
      tenant - the cache owner
      maxCacheSize - the max cache size
      forceExclComp - allows to specify CONFIG_FORCE_EXCLUSIVE_CALCULATION manually instead of reading it from tenant configuration
  • Method Details

    • internalCreateMapInstance

      public CacheMap internalCreateMapInstance(int max)
    • internalCreateMapInstanceStatic

      public static CacheMap internalCreateMapInstanceStatic(Tenant tenant, int max)
    • destroy

      public void destroy()
      Description copied from interface: Cache
      Method called by tennant to free resources before object is finalized
      Specified by:
      destroy in interface Cache
    • 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.
      Specified by:
      getTenant in interface Cache
      Returns:
      the tenant or null if no tenant set
    • getTenantId

      public String getTenantId()
      Specified by:
      getTenantId in interface Cache
    • toString

      public String toString()
      prints out some more or less useful information about this cache instance (like the maximum allowed size)
      Overrides:
      toString in class Object
    • setEnabled

      public void setEnabled(boolean enabled)
      Description copied from interface: Cache
      enables/disables the cache.
      Specified by:
      setEnabled in interface Cache
      Parameters:
      enabled - true for enabling the cache, false otherwise.
    • getSize

      public int getSize()
      the current size of the internal cache (in 'entries')
      Specified by:
      getSize in interface Cache
      Returns:
      the size
    • 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:
      getMaxAllowedSize in interface Cache
      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:
      getMaxReachedSize in interface Cache
    • clear

      public void clear()
      Specified by:
      clear in interface Cache
    • isMultiPathKey

      public static boolean isMultiPathKey(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

      public static List<Object[]> toSingleKey(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:
    • removeUnit

      public void removeUnit(AbstractCacheUnit unit)
      Removes a cache unit from this cache.
      Specified by:
      removeUnit in interface Cache
      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)
      Specified by:
      getUnit in interface Cache
      Returns:
      null if no unit with the given key is in the cache
    • getOrAddUnit

      public AbstractCacheUnit getOrAddUnit(AbstractCacheUnit unit)
      Description copied from interface: Cache
      gets value stored in the cache or loads it.
      Throws exception wrapped into RuntimeException
      Specified by:
      getOrAddUnit in interface Cache
    • getOrAddUnitInternal

      public AbstractCacheUnit getOrAddUnitInternal(AbstractCacheUnit unit, ReadWriteLock rwLock)
    • invalidate

      public void invalidate(Object[] key, int invalidationType)
      execute invalidation (not delayed to transaction end)
      Specified by:
      invalidate in interface Cache
      Specified by:
      invalidate in interface InvalidationTarget
      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:
      getAbstractCacheUnit in interface Cache
    • getAddCount

      public long getAddCount()
      Specified by:
      getAddCount in interface Cache
      Returns:
      how many entities where added to the cache since creation of the cache. This is reseted by calling clear() or clearStats().
    • getRemoveCount

      public long getRemoveCount()
      Specified by:
      getRemoveCount in interface Cache
      Returns:
      how many entities where removed from the cache since creation of the cache. This is reseted by calling clear() or clearStats().
    • getGetCount

      public long getGetCount()
      Specified by:
      getGetCount in interface Cache
      Returns:
      how many entities where requested from the cache since creation of the cache. This is reseted by calling clear() or clearStats().
    • getMissCount

      public long getMissCount()
      Specified by:
      getMissCount in interface Cache
      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() or clearStats().
    • statsEnabled

      public boolean statsEnabled()
      Returns true if the statistics for the cache are enabled. This can be modified with the method enableStats(boolean). Collecting the statistics is very memory intensive - use clearStats() frequently.
      Specified by:
      statsEnabled in interface Cache
      Returns:
      false otherwise.
    • enableStats

      public void enableStats(boolean enabled)
      Enables or disables the cache statistics.
      Specified by:
      enableStats in interface Cache
      Parameters:
      enabled - true for enabling the statistics
    • clearStats

      public void clearStats()
      Clears the collected cache statistics.
      Specified by:
      clearStats in interface Cache
    • isStatsEmpty

      public boolean isStatsEmpty()
      Returns true if no cache statistics are collected. (addToStatistics(Object[], boolean) was not called yet)
      Specified by:
      isStatsEmpty in interface Cache
      Returns:
      false otherwise
    • isForceExclusiveComputation

      public boolean isForceExclusiveComputation()
      Tells AbstractCacheUnit whether value computation should be exclusive (synchronized) or not.
      Specified by:
      isForceExclusiveComputation in interface Cache
    • getStatistics

      public Set getStatistics(int upperBound, int lowerBound)
      Returns as Set the collected cache statistics. Each set entry is a CacheStatisticsEntry. With the parameters upperBound and lowerBound a reduced Set will be returned. CacheStatisticsEntry.getFactor() must be between upperBound and lowerBound.
      Specified by:
      getStatistics in interface Cache
      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 String keyToString(Object[] key)
    • setStatsEnabled

      public void setStatsEnabled(boolean enabled)
      Description copied from interface: Cache
      Enables or disables the cache statistics.
      Specified by:
      setStatsEnabled in interface Cache
      Parameters:
      enabled - true for enabling the statistics