Interface Cache
- All Known Subinterfaces:
InfoCache
,VariantCache
- All Known Implementing Classes:
HeapCache
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 -
Method Summary
Modifier and TypeMethodDescriptionvoid
addObserver
(CacheObserver observer) default void
cleanUp()
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 byCacheWorker
during its shifts.void
purge()
Deletes the entire cache contents.default void
shutdown()
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
- Parameters:
observer
- Instance to add. A weak reference to it will be maintained, so there will be no need to remove it later.
-
cleanUp
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
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
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 byCacheWorker
during its shifts. This default implementation callsevictInvalid()
andcleanUp()
. If an implementation has anything else to do, it should override and callsuper
. -
purge
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:
-