# Cache and rate limits (/docs/starter/modules/cache)

Choose with `--cache redis` (default) or `--cache memory`. On [a React + Vite frontend with an API](../../cli/frontend-and-api.mdx#modules-on-these-stacks), the Hono and FastAPI APIs implement both options: see [A frontend and its API](#a-frontend-and-its-api).

<Tabs items={['Redis', 'Memory']} groupId="cache" persist>
  <Tab value="Redis">
    Redis is optional. Set `REDIS_URL` to a TCP connection URL:

    ```dotenv title="apps/web/.env.local"
    REDIS_URL=rediss://default:<password>@<host>:6379
    ```

    Use `rediss://` for TLS connections such as Upstash and `redis://` for an unencrypted connection on a trusted network. The app uses the standard Redis protocol and requires a Node.js runtime with outbound TCP access.

    Without `REDIS_URL`, the rate limiter and cache use process memory. Memory limits apply per server process, so configure Redis when you run several instances or serverless functions. Never commit a real Redis URL or password.
  </Tab>
  <Tab value="Memory">
    The rate limiter and cache keep their state in process memory, which suits a single server instance. Limits and cached values are not shared between instances and reset on restart. Deploy one instance, or switch to Redis with `pnpm clubedge add cache redis` before scaling out.
  </Tab>
</Tabs>

Rate limits count each client by its address. From Starter v0.27.0, `CLIENT_IP_HEADER` or `TRUSTED_PROXY_HOPS` tells the server where to find it for your host; `pnpm clubedge deploy` sets the one for its platform. See [Client addresses](../before-deploying.mdx#client-addresses). Before, client addresses came from `x-forwarded-for`, so deploy behind a proxy that sets it.

## A frontend and its API [#a-frontend-and-its-api]

With the Hono API (Starter v0.25.0 or newer) and the FastAPI API (Starter v0.26.0 or newer), the rate limits and cache are the API's, so `REDIS_URL` belongs in `apps/api/.env.local` and on the API's service. A limit answers `429` with `Retry-After`. When Redis is unreachable, requests go through and the failure is reported. FastAPI uses the same key prefixes as the TypeScript apps, so both can share a Redis database.
