Lotus.Cache (Lotus v1.0.0)

Copy Markdown View Source

Lotus cache facade. If no adapter configured, acts as a no-op pass-through.

Summary

Types

key()

@type key() :: binary()

opts()

@type opts() :: Keyword.t()

ttl_ms()

@type ttl_ms() :: non_neg_integer()

value()

@type value() :: any()

Functions

build_options(cache_opts, tags)

@spec build_options(term(), [String.t()]) :: opts()

Builds the per-entry options for a cache write.

Layers the caller's :cache option over the entry options set in application config, then adds the invalidation tags. A caller that passes no :cache option, or an atom such as :bypass, still gets the configured defaults.

delete(key)

@spec delete(key()) :: :ok | {:error, term()}

enabled?()

@spec enabled?() :: boolean()

get(key)

@spec get(key()) :: {:ok, value()} | :miss

get_or_store(key, ttl_ms, fun, opts \\ [])

@spec get_or_store(key(), ttl_ms(), (-> value()), opts()) ::
  {:ok, value(), :hit | :miss | atom()} | {:error, term()}

invalidate_scope(scope)

@spec invalidate_scope(term()) :: :ok | {:error, term()}

Invalidates all cache entries associated with the given scope.

Uses tag-based invalidation — each scoped cache entry is tagged with "scope:<digest>", so this clears only entries for the specified scope without flushing the entire source cache.

Examples

Lotus.Cache.invalidate_scope(%{tenant_id: 42})
Lotus.Cache.invalidate_scope(%{role: :admin})

invalidate_tags(tags)

@spec invalidate_tags([binary()]) :: :ok | {:error, term()}

put(key, value, ttl_ms, opts \\ [])

@spec put(key(), value(), ttl_ms(), opts()) :: :ok | {:error, term()}