Interface CacheOperation

  • All Known Subinterfaces:
    CacheControl

    public interface CacheOperation
    Commands to influence the cache operation in general.

    All commands return a CompletableFuture. A cache client may choose to wait for the operation to complete or not. As of version 2.0 all operations are completed instantly within the calling thread. This will change in later versions.

    Outlook: Could get ability to control expiry and refresh behavior, as well as disable the cache.

    Since:
    2.0
    Author:
    Jens Wilke
    • Method Detail

      • removeAll

        CompletableFuture<Void> removeAll()
        Removes all cache contents. This has the same semantics of calling remove to every key, except that the cache is trying to optimize the bulk operation. Same as clear but listeners will be called.
      • destroy

        CompletableFuture<Void> destroy()
        A combination of Cache.clear() and Cache.close() wiping all stored data of this cache.

        This method is to future-proof the API, when a persistence feature is added. In this case the method will stop cache operations and remove all stored external data.

        Rationale: The corresponding method in JSR107 is CacheManager.destroyCache().

        Returns:
        See class description
      • changeCapacity

        CompletableFuture<Void> changeCapacity​(long entryCountOrWeight)
        Change the maximum capacity of the cache. If a weigher is present this is the maximum weight of all cache entries, otherwise the maximum count of cache entries.

        The value of 0 has the special function to disable the cache. Disabling the cache is only useful in development or if no concurrent access is happening. When the cache is disabled a cache entries will still be inserted and subsequent load requests on the same entry will block. After every cache operation the entry is immediately expired.

        Parameters:
        entryCountOrWeight - either maximum number of entries or maximum weight
        Returns:
        See class description
        See Also:
        Weigher