Class ImCache

java.lang.Object
io.github.palexdev.imcache.core.ImCache

public class ImCache extends Object

Core class which eases communication between the request system (ImRequest) and the caching system (ImgCache).

A single instance of this class should cover most use cases, that's why it offers a 'default' instance via instance(); however, the no-args constructor is left public in case one needs separate caches.

A request is generated starting from the source URL for a certain resource, which is the most generic way to represent a resource; it can be a network resource, a file or something else. Once a request's execution successfully terminates, it asks the associated ImCache instance to save the result, see store(ImRequest, ImImage, ImImage).

While removals are delegated directly to the Cache, get operations should be done by creating a new request. A resource may or may not be cached anymore at a given time. ImRequest uses ImRequest.RequestState.CACHE_HIT to indicate that the resource was found in the cache, and ImRequest.RequestState.SUCCEEDED to indicate that the resource was loaded from its URL. Of course, since ImCache allows getting the ImgCache instance with storage(), you can perform operations directly on the cache data structure, although it's not recommended unless you really need it for your use case.

The last core concept is Transforms. ImCache does not provide only a way to load and cache images, but also a way to modify them via the Transform.transform(BufferedImage) API. Transformations are applied by ImRequest after the original resource is loaded. At that point we can store the results, but this raises a question: which one do you want to save? ImCache allows you to control this behavior by setting the ImCache.StoreStrategy, see store(ImRequest, ImImage, ImImage). /// The reason the system doesn't allow caching both is to save space and for simplicity Most of the time you probably want to cache the original resource, as transform operations are relatively fast.

Defaults & Config

invalid reference
#storeStrategy(StoreStrategy)
See Also: