Class DefaultCache

    • Field Detail

      • tenantId

        protected final java.lang.String tenantId
    • Constructor Detail

      • 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 Detail

      • 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 java.lang.String getTenantId()
        Specified by:
        getTenantId in interface Cache
      • toString

        public java.lang.String toString()
        prints out some more or less useful information about this cache instance (like the maximum allowed size)
        Overrides:
        toString in class java.lang.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​(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:
        removeUnit in interface Cache
        Parameters:
        unit - the unit to be removed. note that the same of any unit with the same key is removed.
      • invalidate

        public void invalidate​(java.lang.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​(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:
        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
      • getStatistics

        public java.util.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 java.lang.String keyToString​(java.lang.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