# `PhoenixKit.Cache.Registry`
[🔗](https://github.com/BeamLabEU/phoenix_kit/blob/v1.7.102/lib/phoenix_kit/cache/registry.ex#L1)

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)

# `cache_exists?`

```elixir
@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`

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

Child specification for supervision trees.

## Examples

    children = [
      PhoenixKit.Cache.Registry
    ]

# `count`

```elixir
@spec count() :: non_neg_integer()
```

Returns the count of registered cache processes.

## Examples

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

# `get_cache_pid`

```elixir
@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`

```elixir
@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`

```elixir
@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`

```elixir
@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`

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

Starts the Registry for cache process registration.

## Examples

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

# `stats`

```elixir
@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`

```elixir
@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}}

---

*Consult [api-reference.md](api-reference.md) for complete listing*
