Class CacheManager

  extended by org.apache.jackrabbit.core.state.CacheManager
All Implemented Interfaces:

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.

Nested Class Summary
static class CacheManager.CacheInfo
          Internal copy of the cache information.
Field Summary
Fields inherited from interface org.apache.jackrabbit.core.state.CacheAccessListener
Constructor Summary
Method Summary
 void add(Cache cache)
          Add a new cache to the list.
 void cacheAccessed()
          After one of the caches is accessed a number of times, this method is called.
 void disposeCache(Cache cache)
          Called after the cache is no longer used.
 long getMaxMemory()
 long getMaxMemoryPerCache()
 long getMinMemoryPerCache()
 void remove(Cache cache)
          Remove a cache.
 void setMaxMemory(long maxMemory)
 void setMaxMemoryPerCache(long maxMemoryPerCache)
 void setMinMemoryPerCache(long minMemoryPerCache)
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Detail


public CacheManager()
Method Detail


public long getMaxMemory()


public void setMaxMemory(long maxMemory)


public long getMaxMemoryPerCache()


public void setMaxMemoryPerCache(long maxMemoryPerCache)


public long getMinMemoryPerCache()


public void setMinMemoryPerCache(long minMemoryPerCache)


public void cacheAccessed()
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


public void add(Cache cache)
Add a new cache to the list. This call does not trigger recalculating the cache sizes.

cache - the cache to add


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.

cache - the cache to remove


public void disposeCache(Cache cache)
Description copied from interface: CacheAccessListener
Called after the cache is no longer used.

Specified by:
disposeCache in interface CacheAccessListener

Copyright © 2004-2007 The Apache Software Foundation. All Rights Reserved.