Class FastClientRecordCache

java.lang.Object
com.linkedin.venice.fastclient.cache.FastClientRecordCache

public class FastClientRecordCache extends Object
A weight-bounded cache of value bytes exactly as they arrived from the server, keyed by version and serialized key.

The cache is enabled only when a positive byte budget is configured on ClientConfig; otherwise it is never instantiated.

Hybrid entries expire 120 seconds after insertion, independently of metadata refreshes; hits do not extend their lifetime. Batch-only entries have no time-based expiration and survive until version swap. The client clears hybrid entries on successful metadata refreshes, and both version types on observed version swaps. These policies follow the current serving version, not store-level configuration changes. Caching is bypassed when metadata does not identify whether the current serving version is hybrid.

Values are retained compressed and serialized. Keeping them compressed fits more keys into the same budget for stores that enable compression, at the cost of decompressing on each hit. Keeping them serialized means the memory estimate includes the retained byte lengths, and concurrent callers never share a mutable record instance.

Versioned keys isolate late responses from previous versions, even after a version-swap clear. Callers use their request-pinned version for both lookups and fills.

  • Constructor Details

    • FastClientRecordCache

      public FastClientRecordCache(String storeName, long maxSizeInBytes, Supplier<CurrentVersionType> currentVersionTypeSupplier, com.github.benmanes.caffeine.cache.Ticker ticker)
  • Method Details

    • get

      public FastClientRecordCache.CachedValue get(byte[] serializedKey, int version)
      Returns:
      the cached entry, or null if absent.
    • canAdmit

      public boolean canAdmit(int keyLength, int valueLength)
      Call before copying batch response bytes; put rechecks eligibility when a retry winner eventually fills.
    • put

      public void put(byte[] serializedKey, byte[] value, int schemaId, int version)
      Value bytes must be independently owned, not a slice of a batch response, and must not be mutated after insertion.
    • invalidate

      public void invalidate(byte[] serializedKey, int version, FastClientRecordCache.CachedValue expectedValue)
    • logNotInitialized

      public void logNotInitialized()
      Also used when the dispatcher rejects a request before metadata initialization completes.
    • onMetadataRefresh

      public void onMetadataRefresh()
      Called after each successful metadata refresh, including the initial load. Configures expiration from the serving version: 120 seconds after writing for hybrid entries, effectively no time-based expiry for batch-only. Failed refreshes leave the existing policy and entry ages unchanged.

      Clears entries on a type change before applying the new lifetime, and on every successful hybrid refresh. Unchanged batch-only refreshes preserve entries; version-swap invalidation is handled separately. Unknown types clear entries and disable caching until a successful refresh supplies a known type.

    • clear

      public void clear()
      Drop every entry.
    • close

      public void close()
      Permanently disable caching and release entries. An insertion racing with close removes its entry before returning. Unlike metadata-refresh clearing, closing does not permit late responses to refill the cache.
    • getEntryCount

      public long getEntryCount()
    • getEstimatedWeightInBytes

      public long getEstimatedWeightInBytes()
      Caffeine's estimated eviction weight: serialized key bytes, compressed value bytes and a flat entry allowance. This is not measured heap usage. Read only when scraping metrics, never on a request's serving path.