ExStorageService.CloudCache.LocalStore (ex_storage_service v0.6.3)

Copy Markdown View Source

Local read-cache for cloud-backed buckets.

Objects fetched from the remote cloud are stored on disk under: {data_root}/{bucket}/cache/{hash_prefix_2}/{hash_rest}

An LRU index is maintained in Concord under "cloud_cache_index:{bucket}". Each entry tracks the object key → {content_hash, size, last_accessed_at}.

When the total cached size exceeds cache_max_bytes, the least-recently-used entries are evicted until the cache fits within the limit.

Summary

Functions

Clear the entire local cache for a bucket (deletes all cache files and index).

Remove an object from the local cache (index + disk file, if no other index entries reference the same content hash).

Check whether an object is in the local cache.

Store an object in the local cache.

Return cache statistics for a bucket.

Functions

clear(bucket)

@spec clear(String.t()) :: :ok

Clear the entire local cache for a bucket (deletes all cache files and index).

delete(bucket, key)

@spec delete(String.t(), String.t()) :: :ok

Remove an object from the local cache (index + disk file, if no other index entries reference the same content hash).

get(bucket, key)

@spec get(String.t(), String.t()) :: {:ok, String.t()} | :miss

Check whether an object is in the local cache.

Returns {:ok, file_path} on a cache hit, or :miss if not cached. Also updates last_accessed_at on a hit.

put(bucket, key, data, config)

@spec put(String.t(), String.t(), binary(), ExStorageService.CloudCache.Config.t()) ::
  {:ok, String.t()} | {:error, term()}

Store an object in the local cache.

data is the raw binary content. The content hash is computed here. After storing, LRU eviction is triggered if needed.

Returns {:ok, file_path} on success, {:error, reason} on failure.

stats(bucket, max_bytes)

@spec stats(String.t(), non_neg_integer()) :: map()

Return cache statistics for a bucket.

Returns %{count: N, total_bytes: N, max_bytes: N}.