Class RegionCacheAdapter

java.lang.Object
de.hybris.platform.cache.impl.StaticCache
de.hybris.platform.cache.impl.RegionCacheAdapter
All Implemented Interfaces:
Cache, InvalidationTarget, CacheLifecycleCallback

public class RegionCacheAdapter extends StaticCache implements Cache, CacheLifecycleCallback
Class adapts calls to the de.hybris.platform.regioncache.CacheController class.
It is used by AbstractCacheUnit to perform cache operations on regioncache implementations.
  • Constructor Details

  • Method Details

    • getMaxAllowedSize

      public int getMaxAllowedSize()
      Gets total cache size for all regions.
      Specified by:
      getMaxAllowedSize in interface Cache
      Returns:
      the max allowed size
    • invalidate

      public void invalidate(Object[] key, int invalidationType)
      Invokes de.hybris.platform.regioncache.CachegetController().invalidate()
      Specified by:
      invalidate in interface Cache
      Specified by:
      invalidate in interface InvalidationTarget
      Parameters:
      key - may be an incomplete key, for group invalidation
    • getOrAddUnit

      public AbstractCacheUnit getOrAddUnit(AbstractCacheUnit unit)
      Invokes de.hybris.platform.regioncache.CachegetController().getOrAddUnit()
      Specified by:
      getOrAddUnit in interface Cache
    • removeUnit

      public void removeUnit(AbstractCacheUnit unit)
      Removes value from the 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.
    • isForceExclusiveComputation

      public boolean isForceExclusiveComputation()
      We do not load in AbstractCacheUnit.load() (see its comment). This is affecting AbstractCacheUnit.compute(). We have to support old cache flag for this since each cache region is configured separately.
      Specified by:
      isForceExclusiveComputation in interface Cache
    • clear

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

      public Tenant getTenant()
      Description copied from interface: Cache
      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
    • 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.
    • 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 Cache.clear() or Cache.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 Cache.clear() or Cache.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 Cache.clear() or Cache.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 Cache.clear() or Cache.clearStats().
    • statsEnabled

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

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

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

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

      public int getMaxReachedSize()
      Description copied from interface: Cache
      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
    • getUnit

      Specified by:
      getUnit in interface Cache
      Returns:
      null if no unit with the given key is in the cache
      Throws:
      CacheRegionNotSpecifiedException
    • getStatistics

      public Set<? extends CacheStatisticsEntry> getStatistics(int upperBound, int lowerBound)
      Description copied from interface: Cache
      Returns as Set the collected cache statistics. Each set entry is a DefaultCacheStatisticsEntry. With the parameters upperBound and lowerBound a reduced Set will be returned. DefaultCacheStatisticsEntry.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 DefaultCacheStatisticsEntry.
    • getAbstractCacheUnit

      public AbstractCacheUnit getAbstractCacheUnit(String firstKeyElement, String secondKeyElement, String thirdKeyElement, PK fourthKeyElement)
      Description copied from interface: Cache
      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
    • getTenantId

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

      public void enableStats(boolean enabled)
      Specified by:
      enableStats in interface Cache
    • getSize

      public int getSize()
      Specified by:
      getSize in interface Cache
    • 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
    • onAfterAdd

      public void onAfterAdd(CacheKey key, Object value, CacheRegion region)
      Description copied from interface: CacheLifecycleCallback
      Executes after an object has been added to the cache.
      Specified by:
      onAfterAdd in interface CacheLifecycleCallback
    • onAfterRemove

      public void onAfterRemove(CacheKey key, Object value, CacheRegion region)
      Description copied from interface: CacheLifecycleCallback
      Executes after an object has been removed from the cache.
      Specified by:
      onAfterRemove in interface CacheLifecycleCallback
    • onAfterEviction

      public void onAfterEviction(CacheKey key, Object value, CacheRegion region)
      Description copied from interface: CacheLifecycleCallback
      Executes after an object has been evicted from the cache.
      Specified by:
      onAfterEviction in interface CacheLifecycleCallback
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      For sake of registering only one adapter in controller
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • onMissLoad

      public void onMissLoad(CacheKey key, Object value, CacheRegion lruCacheRegion)
      Description copied from interface: CacheLifecycleCallback
      Executes after an object has been loaded but not added to the cache.
      Specified by:
      onMissLoad in interface CacheLifecycleCallback