Overview | Package | Class | Deprecated | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.exist.storage.cache
Class GClockCache

    java.lang.Object
      org.exist.storage.cache.GClockCache

All Implemented Interfaces:
  Cache

Direct Known Subclasses:
  LRDCache

public class GClockCache
extends java.lang.Object
implements Cache

Cache implementation based on the GClock algorithm. Implements a mixture between LFU (Last Frequently Used) and LRU (Last Recently Used) replacement policies. The class uses reference counts to track references to cached objects. Each call to the add method increments the reference count of the object. If the cache is full, the object to be removed is determined by decrementing the reference count for each object until an object with reference count = 0 is found. The implementation tends to replace younger objects first.

Author:
  wolf

Field Summary

Fields inherited from interface org.exist.storage.cache.Cache
`LOG`

Constructor Summary
`GClockCache(int size, double growthFactor, double growthThreshold)`

Method Summary
`void` | `add(Cacheable item)` Add the item to the cache.
`void` | `add(Cacheable item, int initialRefCount)` Add the item to the cache.
`boolean` | `flush()` Call release on all items, but without actually removing them from the cache.
`Cacheable` | `get(Cacheable item)` Retrieve an item from the cache.
`Cacheable` | `get(long key)` Retrieve an item by its key.
`int` | `getBuffers()` Get the size of this cache.
`int` | `getFails()` Get the number of times where an object could not be found in the cache.
`java.lang.String` | `getFileName()`
`double` | `getGrowthFactor()` Returns the factor by which the cache should grow if it can be resized.
`int` | `getHits()` Get the number of times where an object has been successfully loaded from the cache.
`int` | `getLoad()`
`int` | `getThrashing()`
`int` | `getUsedBuffers()` Get the number of buffers currently used.
`boolean` | `hasDirtyItems()` Returns true if the cache contains any dirty items that need to be written to disk.
`void` | `remove(Cacheable item)` Remove an item from the cache.
`void` | `resize(int newSize)` Resize the cache.
`void` | `setCacheManager(CacheManager manager)` Set the CacheManager object that controls this cache.
`void` | `setFileName(java.lang.String name)`

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

Constructor Detail

### GClockCache

    public GClockCache(int size,
                       double growthFactor,
                       double growthThreshold)

Method Detail

### add

    public void add(Cacheable item)

  Description copied from interface: `Cache`
  Add the item to the cache. If it is already in the cache, update the references.

  Specified by:
    `add` in interface `Cache`
  Parameters:
    `item` -

### add

    public void add(Cacheable item,
                    int initialRefCount)

  Description copied from interface: `Cache`
  Add the item to the cache. If it is already in the cache, update the references.

  Specified by:
    `add` in interface `Cache`
  Parameters:
    `item` -
    `initialRefCount` - the initial reference count for the item

### get

    public Cacheable get(Cacheable item)

  Description copied from interface: `Cache`
  Retrieve an item from the cache.

  Specified by:
    `get` in interface `Cache`
  Parameters:
    `item` -
  Returns:
    the item in the cache or null if it does not exist.

### get

    public Cacheable get(long key)

  Description copied from interface: `Cache`
  Retrieve an item by its key.

  Specified by:
    `get` in interface `Cache`
  Parameters:
    `key` - a unique key, usually the page number
  Returns:
    the item in the cache or null if it does not exist.

### remove

    public void remove(Cacheable item)

  Description copied from interface: `Cache`
  Remove an item from the cache.

  Specified by:
    `remove` in interface `Cache`
  Parameters:
    `item` -

### flush

    public boolean flush()

  Description copied from interface: `Cache`
  Call release on all items, but without actually removing them from the cache. This gives the items a chance to write all unwritten data to disk.

  Specified by:
    `flush` in interface `Cache`

### hasDirtyItems

    public boolean hasDirtyItems()

  Description copied from interface: `Cache`
  Returns true if the cache contains any dirty items that need to be written to disk.

  Specified by:
    `hasDirtyItems` in interface `Cache`

### getBuffers

    public int getBuffers()

  Description copied from interface: `Cache`
  Get the size of this cache.

  Specified by:
    `getBuffers` in interface `Cache`
  Returns:
    size

### getUsedBuffers

    public int getUsedBuffers()

  Description copied from interface: `Cache`
  Get the number of buffers currently used.

  Specified by:
    `getUsedBuffers` in interface `Cache`

### getGrowthFactor

    public double getGrowthFactor()

  Description copied from interface: `Cache`
  Returns the factor by which the cache should grow if it can be resized. The returned factor f will be between 0 and 2. A value smaller or equal to 1 means the cache can't grow, 1.5 means it grows by 50 percent. A cache with growth factor <= 1.0 can also not be shrinked. A cache is resized by the `CacheManager`.

  Specified by:
    `getGrowthFactor` in interface `Cache`
  Returns:
    growth factor

### getHits

    public int getHits()

  Description copied from interface: `Cache`
  Get the number of times where an object has been successfully loaded from the cache.

  Specified by:
    `getHits` in interface `Cache`

### getFails

    public int getFails()

  Description copied from interface: `Cache`
  Get the number of times where an object could not be found in the cache.

  Specified by:
    `getFails` in interface `Cache`
  Returns:
    number of times where an object could not be found in the cache

### getThrashing

    public int getThrashing()

### setCacheManager

    public void setCacheManager(CacheManager manager)

  Description copied from interface: `Cache`
  Set the CacheManager object that controls this cache.

  Specified by:
    `setCacheManager` in interface `Cache`
  Parameters:
    `manager` -

### resize

    public void resize(int newSize)

  Description copied from interface: `Cache`
  Resize the cache. This method is called by the `CacheManager`. The newSize parameter can either be larger or smaller than the current cache size.

  Specified by:
    `resize` in interface `Cache`
  Parameters:
    `newSize` - the new size of the cache.

### getLoad

    public int getLoad()

  Specified by:
    `getLoad` in interface `Cache`

### setFileName

    public void setFileName(java.lang.String name)

  Specified by:
    `setFileName` in interface `Cache`

### getFileName

    public java.lang.String getFileName()

  Specified by:
    `getFileName` in interface `Cache`

Overview | Package | Class | Deprecated | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright (C) Wolfgang Meier. All rights reserved.