loci.formats.cache

## Class Cache

- java.lang.Object
- - loci.formats.cache.Cache

- All Implemented Interfaces:
    CacheReporter

      public class Cache
      extends java.lang.Object
      implements CacheReporter

  Cache provides a means of managing subsets of large collections of image planes in memory. Each cache has a source, which provides image planes or other objects from somewhere (typically derived from an IFormatReader), and a strategy dictating which image planes should be loaded into the cache, in which order, and which planes should be dropped from the cache. The essence of the logic is the idea that the cache has a "current" position across the multidimensional image series's dimensional axes, with the strategy indicating which surrounding planes to load into the cache (i.e., planes within a certain range along each dimensional axis).

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected boolean` | `autoUpdate` Whether the cache should automatically update when a parameter changes.
    `protected java.lang.Object[]` | `cache` Master array containing cached objects.
    `protected int[]` | `currentPos` Current dimensional position.
    `protected boolean[]` | `inCache` Whether each position is currently supposed to be cached.
    `protected java.util.Vector<CacheListener>` | `listeners` List of cache event listeners.
    `protected ICacheSource` | `source` Current cache source.
    `protected ICacheStrategy` | `strategy` Current cache strategy.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `Cache(ICacheStrategy strategy, ICacheSource source, boolean autoUpdate)` Constructs an object cache with the given cache strategy and source.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addCacheListener(CacheListener l)` Adds a listener for status update events.
    `CacheListener[]` | `getCacheListeners()` Gets a list of all registered status update listeners.
    `int[]` | `getCurrentPos()` Gets the current dimensional position.
    `java.lang.Object` | `getObject(int[] pos)` Gets the cached object at the given dimensional position.
    `ICacheSource` | `getSource()` Gets the cache's caching source.
    `ICacheStrategy` | `getStrategy()` Gets the cache's caching strategy.
    `boolean` | `isInCache(int pos)` Returns true if the object at the given index is in the cache.
    `boolean` | `isInCache(int[] pos)` Returns true if the object at the given dimensional position is in the cache.
    `protected void` | `notifyListeners(CacheEvent e)` Informs listeners of a cache update.
    `void` | `recache()` Updates all planes on the load list.
    `void` | `recache(int n)` Updates the given plane.
    `void` | `removeCacheListener(CacheListener l)` Removes a listener for status update events.
    `void` | `reset()` Reallocates the cache.
    `void` | `setCurrentPos(int[] pos)` Sets the current dimensional position.
    `void` | `setSource(ICacheSource source)` Sets the cache's caching source.
    `void` | `setStrategy(ICacheStrategy strategy)` Sets the cache's caching strategy.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### strategy

          protected ICacheStrategy strategy

      Current cache strategy.

    - #### source

          protected ICacheSource source

      Current cache source.

    - #### currentPos

          protected int[] currentPos

      Current dimensional position.

    - #### cache

          protected java.lang.Object[] cache

      Master array containing cached objects.

    - #### inCache

          protected boolean[] inCache

      Whether each position is currently supposed to be cached.

    - #### listeners

          protected java.util.Vector<CacheListener> listeners

      List of cache event listeners.

    - #### autoUpdate

          protected boolean autoUpdate

      Whether the cache should automatically update when a parameter changes.

  - ### Constructor Detail

    - #### Cache

          public Cache(ICacheStrategy strategy,
                       ICacheSource source,
                       boolean autoUpdate)
                throws CacheException

      Constructs an object cache with the given cache strategy and source.
      Throws:
        `CacheException`

  - ### Method Detail

    - #### getObject

          public java.lang.Object getObject(int[] pos)
                                     throws CacheException

      Gets the cached object at the given dimensional position.
      Throws:
        `CacheException`

    - #### isInCache

          public boolean isInCache(int[] pos)
                            throws CacheException

      Returns true if the object at the given dimensional position is in the cache.
      Throws:
        `CacheException`

    - #### isInCache

          public boolean isInCache(int pos)
                            throws CacheException

      Returns true if the object at the given index is in the cache.
      Throws:
        `CacheException`

    - #### reset

          public void reset()
                     throws CacheException

      Reallocates the cache.
      Throws:
        `CacheException`

    - #### getStrategy

          public ICacheStrategy getStrategy()

      Gets the cache's caching strategy.

    - #### getSource

          public ICacheSource getSource()

      Gets the cache's caching source.

    - #### getCurrentPos

          public int[] getCurrentPos()

      Gets the current dimensional position.

    - #### setStrategy

          public void setStrategy(ICacheStrategy strategy)
                           throws CacheException

      Sets the cache's caching strategy.
      Throws:
        `CacheException`

    - #### setSource

          public void setSource(ICacheSource source)
                         throws CacheException

      Sets the cache's caching source.
      Throws:
        `CacheException`

    - #### setCurrentPos

          public void setCurrentPos(int[] pos)
                             throws CacheException

      Sets the current dimensional position.
      Throws:
        `CacheException`

    - #### recache

          public void recache(int n)
                       throws CacheException

      Updates the given plane.
      Throws:
        `CacheException`

    - #### recache

          public void recache()
                       throws CacheException

      Updates all planes on the load list.
      Throws:
        `CacheException`

    - #### addCacheListener

          public void addCacheListener(CacheListener l)

      Description copied from interface: `CacheReporter`
      Adds a listener for status update events.
      Specified by:
        `addCacheListener` in interface `CacheReporter`

    - #### removeCacheListener

          public void removeCacheListener(CacheListener l)

      Description copied from interface: `CacheReporter`
      Removes a listener for status update events.
      Specified by:
        `removeCacheListener` in interface `CacheReporter`

    - #### getCacheListeners

          public CacheListener[] getCacheListeners()

      Description copied from interface: `CacheReporter`
      Gets a list of all registered status update listeners.
      Specified by:
        `getCacheListeners` in interface `CacheReporter`

    - #### notifyListeners

          protected void notifyListeners(CacheEvent e)

      Informs listeners of a cache update.

Copyright © 2026 Open Microscopy Environment