macula_pubsub_cache (macula v0.20.5)

View Source

LRU cache for remote subscriber lists. Caches DHT query results to avoid repeated lookups. Wraps macula_cache with subscriber-specific logic.

Summary

Functions

Clear all entries.

Get entry from cache. Returns {ok, Subscribers, UpdatedCache} or not_found. The updated cache has the entry moved to front (LRU).

Invalidate (remove) entry.

Check if entry is expired based on TTL. This checks if entry exists and its age exceeds TTL.

Get max size.

Create new cache with max size.

Put entry in cache.

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, Pattern)

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

Get entry from cache. Returns {ok, Subscribers, UpdatedCache} or not_found. The updated cache has the entry moved to front (LRU).

invalidate(Cache, Pattern)

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

Invalidate (remove) entry.

is_expired(Cache, Pattern, TTL)

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

Check if entry is expired based on TTL. This checks if entry exists and its age exceeds TTL.

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, Pattern, Subscribers)

-spec put(cache(), binary(), [map()]) -> cache().

Put entry in cache.

put_with_timestamp(Cache, Pattern, Subscribers, Timestamp)

-spec put_with_timestamp(cache(), binary(), [map()], integer()) -> cache().

Put entry with custom timestamp (for testing).

size(Cache)

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

Get number of entries.