org.apache.jackrabbit.core.cache
Class CacheManager

java.lang.Object
  extended by org.apache.jackrabbit.core.cache.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.


Nested Class Summary
static class CacheManager.CacheInfo
          Internal copy of the cache information.
 
Field Summary
 
Fields inherited from interface org.apache.jackrabbit.core.cache.CacheAccessListener
ACCESS_INTERVAL
 
Constructor Summary
CacheManager()
           
 
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()
           
 long getMinResizeInterval()
           
 void remove(Cache cache)
          Remove a cache.
 void setMaxMemory(long maxMemory)
           
 void setMaxMemoryPerCache(long maxMemoryPerCache)
           
 void setMinMemoryPerCache(long minMemoryPerCache)
           
 void setMinResizeInterval(long minResizeInterval)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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()
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

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

disposeCache

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-2010 The Apache Software Foundation. All Rights Reserved.