ExMCP.Internal.ConsentCache (ex_mcp v0.10.0)

View Source

A GenServer and ETS-based cache for user consent decisions.

Summary

Functions

Checks for an existing, valid consent in the cache.

Returns a specification to start this module under a supervisor.

Triggers a manual cleanup of expired consent entries.

Clears all consent decisions from the cache.

Revokes a consent decision from the cache.

Starts the ConsentCache GenServer.

Stores a consent decision in the cache.

Functions

check_consent(user_id, resource_origin)

@spec check_consent(
  ExMCP.ConsentHandler.user_id(),
  ExMCP.ConsentHandler.resource_origin()
) ::
  {:ok, expires_at :: non_neg_integer()} | {:not_found} | {:expired}

Checks for an existing, valid consent in the cache.

This performs a direct ETS lookup for performance.

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

cleanup_expired()

Triggers a manual cleanup of expired consent entries.

clear()

Clears all consent decisions from the cache.

This is primarily intended for testing purposes to ensure test isolation.

revoke_consent(user_id, resource_origin)

Revokes a consent decision from the cache.

start_link(opts)

Starts the ConsentCache GenServer.

store_consent(user_id, resource_origin, expires_at)

@spec store_consent(
  ExMCP.ConsentHandler.user_id(),
  ExMCP.ConsentHandler.resource_origin(),
  expires_at :: non_neg_integer()
) :: :ok

Stores a consent decision in the cache.

expires_at is a monotonic time in seconds.