PhoenixKit.Cache.Registry (phoenix_kit v1.6.15)

View Source

Lightweight Registry wrapper for PhoenixKit.Cache instances.

This module provides simple process registration and discovery for cache processes.

Features

  • Simple Registry wrapper using Elixir's Registry
  • Process registration and discovery
  • Basic cache listing and health checking

Usage

# Register a cache process (typically done automatically)
{:ok, pid} = PhoenixKit.Cache.start_link(name: :my_cache)

# List all registered caches
PhoenixKit.Cache.Registry.list_caches()

# Check if a cache is registered
PhoenixKit.Cache.Registry.cache_exists?(:my_cache)

# Get cache process PID
PhoenixKit.Cache.Registry.get_cache_pid(:my_cache)

Summary

Functions

Checks if a cache is registered and running.

Child specification for supervision trees.

Returns the count of registered cache processes.

Gets the PID of a registered cache process.

Performs a basic health check on registered caches.

Lists all registered cache instances with their basic status.

Looks up a cache process by name.

Starts the Registry for cache process registration.

Gets basic statistics for registered caches.

Creates a via tuple for process registration.

Functions

cache_exists?(name)

@spec cache_exists?(atom()) :: boolean()

Checks if a cache is registered and running.

Examples

iex> PhoenixKit.Cache.Registry.cache_exists?(:my_cache)
true

child_spec(_)

@spec child_spec(any()) :: Supervisor.child_spec()

Child specification for supervision trees.

Examples

children = [
  PhoenixKit.Cache.Registry
]

count()

@spec count() :: non_neg_integer()

Returns the count of registered cache processes.

Examples

iex> PhoenixKit.Cache.Registry.count()
2

get_cache_pid(name)

@spec get_cache_pid(atom()) :: pid() | nil

Gets the PID of a registered cache process.

Examples

iex> PhoenixKit.Cache.Registry.get_cache_pid(:my_cache)
#PID<0.123.0>

health_check()

@spec health_check() :: map()

Performs a basic health check on registered caches.

Examples

PhoenixKit.Cache.Registry.health_check()
# => %{
#   overall_status: :healthy,
#   total_caches: 2,
#   running_caches: 2,
#   dead_caches: 0,
#   registry_status: :running
# }

list_caches()

@spec list_caches() :: map()

Lists all registered cache instances with their basic status.

Examples

PhoenixKit.Cache.Registry.list_caches()
# => %{
#   settings: %{pid: #PID<0.123.0>, status: :running},
#   user_roles: %{pid: #PID<0.124.0>, status: :running}
# }

lookup(key)

@spec lookup(atom()) :: [{pid(), any()}]

Looks up a cache process by name.

Examples

iex> PhoenixKit.Cache.Registry.lookup(:my_cache)
[{#PID<0.123.0>, nil}]

start_link()

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

Starts the Registry for cache process registration.

Examples

{:ok, _pid} = PhoenixKit.Cache.Registry.start_link()

stats(cache_name \\ nil)

@spec stats(atom() | nil) :: map()

Gets basic statistics for registered caches.

Note: This provides basic registry-level stats. For detailed cache statistics, use PhoenixKit.Cache.stats/1 directly.

Examples

PhoenixKit.Cache.Registry.stats()
# => %{
#   total_caches: 2,
#   running_caches: 2,
#   dead_caches: 0,
#   cache_names: [:settings, :user_roles]
# }

PhoenixKit.Cache.Registry.stats(:my_cache)
# => %{registered: true, running: true, pid: #PID<0.123.0>}

via_tuple(key)

@spec via_tuple(atom()) :: {:via, Registry, {atom(), atom()}}

Creates a via tuple for process registration.

Examples

iex> PhoenixKit.Cache.Registry.via_tuple(:my_cache)
{:via, Registry, {PhoenixKit.Cache.Registry, :my_cache}}