ProtoRune.Atproto.Identity.Cache (proto_rune v0.2.0)

Copy Markdown

Provides caching for AT Protocol identity resolution results.

This module maintains two ETS tables:

  • handle_cache: Maps handles to DIDs with TTL
  • did_cache: Stores DID documents with TTL

The cache automatically expires entries and provides concurrent access with proper cleanup.

Summary

Functions

Returns a specification to start this module under a supervisor.

Gets a cached DID for a handle. Returns {:ok, did} if found and not expired, otherwise {:error, reason}.

Gets a cached DID document. Returns {:ok, doc} if found and not expired, otherwise {:error, reason}.

Invalidates cached data for a DID.

Invalidates cached data for a handle.

Stores a handle -> DID mapping in the cache.

Stores a DID document in the cache.

Returns cache statistics.

Types

cache_key()

@type cache_key() :: String.t()

cache_value()

@type cache_value() :: term()

ttl()

@type ttl() :: non_neg_integer()

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

get_did(handle)

@spec get_did(String.t()) :: {:ok, String.t()} | {:error, atom()}

Gets a cached DID for a handle. Returns {:ok, did} if found and not expired, otherwise {:error, reason}.

get_did_doc(did)

@spec get_did_doc(String.t()) :: {:ok, map()} | {:error, atom()}

Gets a cached DID document. Returns {:ok, doc} if found and not expired, otherwise {:error, reason}.

invalidate_did(did)

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

Invalidates cached data for a DID.

invalidate_handle(handle)

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

Invalidates cached data for a handle.

put_did(handle, did, opts \\ [])

@spec put_did(String.t(), String.t(), keyword()) :: :ok

Stores a handle -> DID mapping in the cache.

put_did_doc(did, doc, opts \\ [])

@spec put_did_doc(String.t(), map(), keyword()) :: :ok

Stores a DID document in the cache.

start_link(opts \\ [])

stats()

@spec stats() :: map()

Returns cache statistics.