## org.exist.storage
Class CacheManager

    java.lang.Object
      org.exist.storage.CacheManager

public class CacheManager
extends java.lang.Object

CacheManager maintains a global memory pool available to all page caches. All caches start with a low default setting, but CacheManager can grow individual caches until the total memory is reached. Caches can also be shrinked if their "load" remains below a given threshold between check intervals.The check interval is determined by the global sync background thread. The class computes the available memory in terms of pages.

Author:
  wolf

Field Summary
`static int` `DEFAULT_CACHE_SIZE`
`static double` `MAX_MEM_USE` The maximum fraction of the total memory that can be used by a single cache.
`static double` `MIN_SHRINK_FACTOR` The minimum size a cache needs to have to be considered for shrinking, defined in terms of a fraction of the overall memory.
`static java.lang.String` `PROPERTY_CACHE_SIZE`
`static double` `SHRINK_FACTOR` The amount by which a large cache will be shrinked if other caches request a resize.
`static int` `SHRINK_THRESHOLD` The minimum number of pages that must be read from a cache between check intervals to be not considered for shrinking.

Constructor Summary
`CacheManager(Configuration config)`

Method Summary
`void` `checkCaches()` Called from the global major sync event to check if caches can be shrinked.
`void` `checkDistribution()` Called from the global minor sync event to check if a smaller cache wants to be resized.
`void` `deregisterCache(Cache cache)`
`int` `getDefaultInitialSize()` Returns the default initial size for all caches.
`void` `registerCache(Cache cache)` Register a cache, i.e.
`int` `requestMem(Cache cache)` Called by a cache if it wants to grow.

Methods inherited from class java.lang.Object
`equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### MAX_MEM_USE

    public static final double MAX_MEM_USE

  The maximum fraction of the total memory that can be used by a single cache.

  See Also:
    Constant Field Values

### MIN_SHRINK_FACTOR

    public static final double MIN_SHRINK_FACTOR

  The minimum size a cache needs to have to be considered for shrinking, defined in terms of a fraction of the overall memory.

  See Also:
    Constant Field Values

### SHRINK_FACTOR

    public static final double SHRINK_FACTOR

  The amount by which a large cache will be shrinked if other caches request a resize.

  See Also:
    Constant Field Values

### SHRINK_THRESHOLD

    public static final int SHRINK_THRESHOLD

  The minimum number of pages that must be read from a cache between check intervals to be not considered for shrinking. This is a measure for the "load" of the cache. Caches with high load will never be shrinked.

  See Also:
    Constant Field Values

### DEFAULT_CACHE_SIZE

    public static int DEFAULT_CACHE_SIZE

### PROPERTY_CACHE_SIZE

    public static final java.lang.String PROPERTY_CACHE_SIZE

See Also:
  Constant Field Values

Constructor Detail

### CacheManager

    public CacheManager(Configuration config)

Method Detail

### registerCache

    public void registerCache(Cache cache)

  Register a cache, i.e. put it under control of the cache manager.

  Parameters:
    `cache` -

### deregisterCache

    public void deregisterCache(Cache cache)

### requestMem

    public int requestMem(Cache cache)

  Called by a cache if it wants to grow. The cache manager will either deny the request, for example, if there are no spare pages left, or calculate a new cache size and call the cache's `Cache.resize(int)` method to resize the cache. The amount of pages by which the cache will grow is determined by the cache's growthFactor: `Cache.getGrowthFactor()`.

  Parameters:
    `cache` -
  Returns:
    new cache size, or -1 if no free pages available.

### checkCaches

    public void checkCaches()

  Called from the global major sync event to check if caches can be shrinked. To be shrinked, the size of a cache needs to be larger than the factor defined by `MIN_SHRINK_FACTOR` and its load needs to be lower than `SHRINK_THRESHOLD`. If shrinked, the cache will be reset to the default initial cache size.

### checkDistribution

    public void checkDistribution()

  Called from the global minor sync event to check if a smaller cache wants to be resized. If a huge cache is availabe, the method might decide to shrink this cache by a certain amount to make room for the smaller cache to grow.

### getDefaultInitialSize

    public int getDefaultInitialSize()

  Returns the default initial size for all caches.

  Returns:
    Default initial size 64.

Copyright (C) Wolfgang Meier. All rights reserved.