Interface Cache

All Known Subinterfaces:
InfoCache, VariantCache
All Known Implementing Classes:
HeapCache

public sealed interface Cache permits VariantCache, InfoCache

Stores and retrieves unique images corresponding to OperationList instances, as well as Info instances corresponding to Identifier instances.

Implementations typically use a least-recently-used (LRU) strategy, but may also use a least-frequently-used (LFU) or some other strategy.

Implementations are shared across threads and must be thread-safe.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final org.slf4j.Logger
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
     
    default void
    Cleans up the cache.
    void
    evict(Identifier identifier)
    Deletes all cached content (source image, variant image(s), and info) corresponding to the image with the given identifier.
    void
    Deletes invalid images and dimensions from the cache.
    default void
    Implementations should perform all necessary initialization in this method rather than a constructor or static initializer.
    default void
    Called by CacheWorker during its shifts.
    void
    Deletes the entire cache contents.
    default void
    Shuts down the instance, freeing any resource handles, stopping any worker threads, etc.
  • Field Details

    • LOGGER

      static final org.slf4j.Logger LOGGER
  • Method Details

    • addObserver

      void addObserver(CacheObserver observer)
      Parameters:
      observer - Instance to add. A weak reference to it will be maintained, so there will be no need to remove it later.
    • cleanUp

      default void cleanUp() throws IOException

      Cleans up the cache.

      This method should not duplicate the behavior of any of the purging-related methods. Other than that, implementations may use their own interpretation of "clean up"—ideally, they will not need to do anything at all.

      The frequency with which this method will be called may vary. It may never be called. Implementations should try to keep themselves clean without relying on this method.

      The default implementation does nothing.

      Throws:
      IOException - Upon fatal error. Implementations should swallow and log non-fatal errors.
      See Also:
    • evict

      void evict(Identifier identifier) throws IOException
      Deletes all cached content (source image, variant image(s), and info) corresponding to the image with the given identifier.
      Parameters:
      identifier - Identifier of the image whose content to evict.
      Throws:
      IOException - Upon fatal error. Implementations should swallow and log non-fatal errors.
    • evictInvalid

      void evictInvalid() throws IOException
      Deletes invalid images and dimensions from the cache.
      Throws:
      IOException - Upon fatal error. Implementations should swallow and log non-fatal errors.
    • initialize

      default void initialize()

      Implementations should perform all necessary initialization in this method rather than a constructor or static initializer.

      The default implementation does nothing.

    • onCacheWorker

      default void onCacheWorker()
      Called by CacheWorker during its shifts. This default implementation calls evictInvalid() and cleanUp(). If an implementation has anything else to do, it should override and call super.
    • purge

      void purge() throws IOException
      Deletes the entire cache contents.
      Throws:
      IOException - Upon fatal error. Implementations should swallow and log non-fatal errors.
    • shutdown

      default void shutdown()

      Shuts down the instance, freeing any resource handles, stopping any worker threads, etc.

      The default implementation does nothing.

      See Also: