Interface BlobCache

All Superinterfaces:
AutoCloseable

public interface BlobCache extends AutoCloseable
Caches immutable, server-addressed blob payloads on local disk.

open(BlobCacheConfig) uses the shared Rust DXBC implementation through JNI. Cache methods are synchronous and safe to share through a Client and Worker. A missing or rejected entry is a normal cache outcome; the server remains the source of truth. Close the cache after every client and worker using it has stopped.

try (BlobCache cache = BlobCache.open(
        new BlobCacheConfig("./dex-cache", 256L * 1024 * 1024))) {
    boolean cached = cache.put(blobId, payload);
    Optional<byte[]> value = cache.get(blobId);
}
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Flushes pending cache work and releases native resources.
    void
    delete(String blobId)
    Deletes one cached blob if present.
    void
    Deletes all entries managed by this cache.
    Optional<byte[]>
    get(String blobId)
    Reads and validates one cached blob.
    static BlobCache
    Opens or recovers a disk-backed blob cache.
    boolean
    put(String blobId, byte[] payload)
    Offers one payload to the cache's admission policy.
  • Method Details

    • open

      static BlobCache open(BlobCacheConfig config)
      Opens or recovers a disk-backed blob cache.
      Parameters:
      config - the cache directory, capacity, and admission configuration
      Returns:
      the opened cache
      Throws:
      IllegalArgumentException - if config is null
      RuntimeException - if the native library cannot load or the cache cannot open
    • get

      Optional<byte[]> get(String blobId)
      Reads and validates one cached blob.
      Parameters:
      blobId - the server-minted blob identifier
      Returns:
      a copy of the payload, or an empty value for a cache miss
      Throws:
      RuntimeException - if cache storage cannot be read
    • put

      boolean put(String blobId, byte[] payload)
      Offers one payload to the cache's admission policy.
      Parameters:
      blobId - the server-minted blob identifier
      payload - the immutable payload bytes to cache
      Returns:
      true when admitted and stored; false when policy rejects the entry
      Throws:
      RuntimeException - if cache storage cannot be written
    • delete

      void delete(String blobId)
      Deletes one cached blob if present.
      Parameters:
      blobId - the server-minted blob identifier
      Throws:
      RuntimeException - if cache storage cannot complete the deletion
    • deleteAll

      void deleteAll()
      Deletes all entries managed by this cache.
      Throws:
      RuntimeException - if cache storage cannot complete all deletions
    • close

      void close()
      Flushes pending cache work and releases native resources.

      Do not call other methods after closing the cache.

      Specified by:
      close in interface AutoCloseable