erllama_cache (erllama v0.1.0)

View Source

Public façade for the cache subsystem.

Tier servers, the meta server, the writer pool, and the policy module are internal. The runtime cache plumbing (lookup_exact/1, checkout/2, checkin/1, save_async/N, lookup_exact_or_wait/2) lives in erllama_cache_meta_srv and erllama_cache_writer; this module exposes only the operator-friendly subset.

Summary

Functions

Evict oldest available rows until at least TargetBytes have been freed. Returns {evicted, NumRows, BytesFreed}.

Like evict_bytes/1, but only considers rows whose tier is in Tiers. Pass all to match every tier, or a subset of [ram, ram_file, disk]. The system-pressure scheduler uses this to evict only RAM-resident slabs while leaving the disk tier alone.

Synchronous full eviction pass. Walks the LRU and drops every available row with refcount=0. Returns the number evicted.

Snapshot of operational counters as a map of slot name to non-negative integer. Suitable for forwarding to a metrics exporter (Prometheus, statsd, OpenTelemetry).

Find the longest cached prefix of Tokens for the given key namespace. Stride and floor default to the policy's boundary_align_tokens and min_tokens. Operator-friendly entry point for stateless callers (HTTP front-end, agent loops) that resend the full conversation each turn.

Reset all counters to 0. Mostly for tests; production callers should treat counters as monotonic-since-boot.

Types

cache_key()

-type cache_key() :: <<_:256>>.

save_reason()

-type save_reason() :: cold | continued | finish | evict | shutdown.

status()

-type status() :: available | writing | evicting.

tier()

-type tier() :: ram | ram_file | disk.

Functions

evict_bytes(TargetBytes)

-spec evict_bytes(non_neg_integer()) -> {evicted, non_neg_integer(), non_neg_integer()}.

Evict oldest available rows until at least TargetBytes have been freed. Returns {evicted, NumRows, BytesFreed}.

evict_bytes(TargetBytes, Tiers)

-spec evict_bytes(non_neg_integer(), all | [tier()]) -> {evicted, non_neg_integer(), non_neg_integer()}.

Like evict_bytes/1, but only considers rows whose tier is in Tiers. Pass all to match every tier, or a subset of [ram, ram_file, disk]. The system-pressure scheduler uses this to evict only RAM-resident slabs while leaving the disk tier alone.

gc()

-spec gc() -> {evicted, non_neg_integer()}.

Synchronous full eviction pass. Walks the LRU and drops every available row with refcount=0. Returns the number evicted.

get_counters()

-spec get_counters() -> #{atom() => non_neg_integer()}.

Snapshot of operational counters as a map of slot name to non-negative integer. Suitable for forwarding to a metrics exporter (Prometheus, statsd, OpenTelemetry).

lookup_longest_prefix(KeyMeta, Tokens)

-spec lookup_longest_prefix(map(), [non_neg_integer()]) -> {ok, pos_integer(), tuple()} | miss.

Find the longest cached prefix of Tokens for the given key namespace. Stride and floor default to the policy's boundary_align_tokens and min_tokens. Operator-friendly entry point for stateless callers (HTTP front-end, agent loops) that resend the full conversation each turn.

lookup_longest_prefix(KeyMeta, Tokens, Stride, MinTokens)

-spec lookup_longest_prefix(map(), [non_neg_integer()], pos_integer(), pos_integer()) ->
                               {ok, pos_integer(), tuple()} | miss.

Like lookup_longest_prefix/2 with explicit stride and floor.

reset_counters()

-spec reset_counters() -> ok.

Reset all counters to 0. Mostly for tests; production callers should treat counters as monotonic-since-boot.