# Alepha - Cache

## Installation

Part of the `alepha` package. Import from `alepha/cache`.

```bash
npm install alepha
```

## Overview

Type-safe caching with TTL support.

**Features:**

- Cached computations with type-safe keys and values
- Configurable TTL
- Cache invalidation
- Automatic cache population
- Providers: Redis when `REDIS_URL` is set, Memory otherwise (Node, Bun),
  Cloudflare (workerd), Database (per `$cache`)

Set `REDIS_URL` and every instance shares one cache; leave it unset and the
cache is this process's memory. An app's own `CacheProvider` substitution
wins over both.

## API Reference

### Primitives

- [`$cache`](https://latest.alepha.dev/docs/reference-primitives-$cache.md) - Creates a cache primitive for caching with automatic management.

### Providers

- [`CacheProvider`](https://latest.alepha.dev/docs/reference-providers-cacheprovider.md) - Cache provider interface.
- [`CloudflareCacheProvider`](https://latest.alepha.dev/docs/reference-providers-cloudflarecacheprovider.md) - Cloudflare cache provider: the database cache when the app has one, else KV.
- [`CloudflareKVProvider`](https://latest.alepha.dev/docs/reference-providers-cloudflarekvprovider.md) - Cloudflare KV cache provider.
- [`MemoryCacheProvider`](https://latest.alepha.dev/docs/reference-providers-memorycacheprovider.md) - In-memory implementation of CacheProvider for testing.
- [`RedisCacheProvider`](https://latest.alepha.dev/docs/reference-providers-rediscacheprovider.md) - Cache entries in Redis.
