macula_rpc_cache (macula v0.20.5)

View Source

LRU cache for RPC procedure results. Caches results of idempotent procedures to avoid repeated execution. Wraps macula_cache with RPC-specific logic and TTL handling.

Summary

Functions

Clear all entries.

Get entry from cache. Returns {ok, Result, UpdatedCache} or not_found. The updated cache has the entry moved to front (LRU). Automatically removes expired entries.

Invalidate (remove) entry.

Check if entry is expired.

Make cache key from URI and args. Uses hash of URI and args for consistent key generation.

Get max size.

Create new cache with max size.

Put entry with custom timestamp (for testing).

Get number of entries.

Types

cache/0

-type cache() :: macula_cache:cache().

Functions

clear(Cache)

-spec clear(cache()) -> cache().

Clear all entries.

get(Cache, Uri, Args)

-spec get(cache(), binary(), map()) -> {ok, term(), cache()} | not_found.

Get entry from cache. Returns {ok, Result, UpdatedCache} or not_found. The updated cache has the entry moved to front (LRU). Automatically removes expired entries.

invalidate(Cache, Uri, Args)

-spec invalidate(cache(), binary(), map()) -> cache().

Invalidate (remove) entry.

is_expired(Cache, Uri, Args)

-spec is_expired(cache(), binary(), map()) -> boolean().

Check if entry is expired.

make_key(Uri, Args)

-spec make_key(binary(), map()) -> binary().

Make cache key from URI and args. Uses hash of URI and args for consistent key generation.

max_size(Cache)

-spec max_size(cache()) -> pos_integer().

Get max size.

new(MaxSize)

-spec new(pos_integer()) -> cache().

Create new cache with max size.

put(Cache, Uri, Args, Result, TTL)

-spec put(cache(), binary(), map(), term(), pos_integer()) -> cache().

Put entry in cache.

put_with_timestamp(Cache, Uri, Args, Result, TTL, Timestamp)

-spec put_with_timestamp(cache(), binary(), map(), term(), pos_integer(), integer()) -> cache().

Put entry with custom timestamp (for testing).

size(Cache)

-spec size(cache()) -> non_neg_integer().

Get number of entries.