Search documentation of phoenix_kit

# PhoenixKit.Cache.Registry (phoenix_kit v1.7.87)

Copy Markdown 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

cache_exists?(name)

Checks if a cache is registered and running.

child_spec(_)

Child specification for supervision trees.

count()

Returns the count of registered cache processes.

get_cache_pid(name)

Gets the PID of a registered cache process.

health_check()

Performs a basic health check on registered caches.

list_caches()

Lists all registered cache instances with their basic status.

lookup(key)

Looks up a cache process by name.

start_link()

Starts the Registry for cache process registration.

stats(cache_name \\ nil)

Gets basic statistics for registered caches.

via_tuple(key)

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}}