Class CacheManager

  • All Implemented Interfaces:
    CacheAccessListener

    public class CacheManager
    extends Object
    implements CacheAccessListener
    This class manages the size of the caches used in Jackrabbit. The combined size of all caches must be limited to avoid out of memory problems. The available memory is dynamically distributed across the caches each second. This class tries to calculates the best cache sizes by comparing the access counts of each cache, and the used memory. The idea is, the more a cache is accessed, the more memory it should get, while the cache should not shrink too quickly. A minimum and maximum size per cache is defined as well. After distributing the memory in this way, there might be some unused memory (if one or more caches did not use some of the allocated memory). This unused memory is distributed evenly across the full caches.
    • Constructor Detail

      • CacheManager

        public CacheManager()
    • Method Detail

      • getMaxMemory

        public long getMaxMemory()
      • setMaxMemory

        public void setMaxMemory​(long maxMemory)
      • getMaxMemoryPerCache

        public long getMaxMemoryPerCache()
      • setMaxMemoryPerCache

        public void setMaxMemoryPerCache​(long maxMemoryPerCache)
      • getMinMemoryPerCache

        public long getMinMemoryPerCache()
      • setMinMemoryPerCache

        public void setMinMemoryPerCache​(long minMemoryPerCache)
      • getMinResizeInterval

        public long getMinResizeInterval()
      • setMinResizeInterval

        public void setMinResizeInterval​(long minResizeInterval)
      • cacheAccessed

        public void cacheAccessed​(long accessCount)
        After one of the caches is accessed a number of times, this method is called. Resize the caches if required.
        Specified by:
        cacheAccessed in interface CacheAccessListener
        Parameters:
        accessCount - number of cache accesses since the last call
      • add

        public void add​(Cache cache)
        Add a new cache to the list. This call does not trigger recalculating the cache sizes.
        Parameters:
        cache - the cache to add
      • remove

        public void remove​(Cache cache)
        Remove a cache. As this class only has a weak reference to each cache, calling this method is not strictly required. This call does not trigger recalculating the cache sizes.
        Parameters:
        cache - the cache to remove