Class CacheLayer

java.lang.Object
org.apache.opendal.Layer
org.apache.opendal.layer.CacheLayer
All Implemented Interfaces:
AutoCloseable

public final class CacheLayer extends Layer implements AutoCloseable
Caches aligned chunks of reads in a separate operator.

Sources must expose a verifiable identity (version, a strong etag, or last_modified) to be cached; reads from sources without one pass through directly.

Single-path writes and deletes through the layered operator invalidate cached metadata for the affected paths. External mutations and recursive deletes are bounded by ttl.

Use a cache backend with capacity eviction to reclaim chunks from old object identities. Use separate cache roots or instances for different tenants, endpoints, or credentials because fresh cache hits can skip source I/O.

The layer retains its own reference to the cache operator. The supplied cache handle can be closed after build() returns. Close the layer after applying it to every operator that needs it. Those operators can still use the cache after the layer is closed.

See Also:
  • Method Details

    • builder

      public static CacheLayer.CacheLayerBuilder builder(AsyncOperator cache)
      Creates a builder using an asynchronous cache operator.
      Parameters:
      cache - the cache operator, which must support read, write, and delete
      Returns:
      a new builder
      Throws:
      NullPointerException - if the cache operator is null
    • builder

      public static CacheLayer.CacheLayerBuilder builder(Operator cache)
      Creates a builder using a blocking cache operator.
      Parameters:
      cache - the cache operator, which must support read, write, and delete
      Returns:
      a new builder
      Throws:
      NullPointerException - if the cache operator is null
    • layer

      protected long layer(long nativeOp)
      Specified by:
      layer in class Layer
    • close

      public void close()
      Releases this layer's reference to the cache. Already-layered operators retain theirs.
      Specified by:
      close in interface AutoCloseable