---
title: "Cap the cache server's memory and choose · Agent Wranglers"
url: https://agentwranglers.se/playbook/scaling/caching/cache-memory-and-eviction
updated: 2026-10-21
licence: "CC BY 4.0"
licence_url: https://creativecommons.org/licenses/by/4.0/
---

# Cap the cache server's memory and choose its eviction

For AI agents: the [site map](https://agentwranglers.se/llms.txt) lists everything here, and this page sits under [Caching](https://agentwranglers.se/playbook/scaling/caching.md).

By [Agent Wranglers](https://agentwranglers.se/authors/agent-wranglers). Updated 2026-10-21.

- ID: SCL-14
- Level: Required
- Chapter: [Caching](https://agentwranglers.se/playbook/scaling/caching)
- Rule: Set a memory limit and an eviction policy on every cache server. Keep data that must not be evicted, such as job queues, in a separate instance that never evicts.
- Risk: The app down or unusable
- Applies when: The project runs its own servers, virtual machines or containers.
- How: Redis and Valkey set no memory limit by default on 64-bit systems, so a cache grows until the machine runs out. Set `maxmemory` below the instance's memory, and leave room for replication buffers. For a pure cache, the Redis docs call `allkeys-lru` a good default. A queue needs `noeviction`, which makes writes fail instead of dropping jobs. So a queue and a cache cannot share one policy, and both projects advise two instances. Alert on memory as [Warn before resources run out](https://agentwranglers.se/playbook/operations/capacity-and-cost/exhaustion-alerts) says.
- Check: `CONFIG GET maxmemory` returns a value above 0 on every instance. Cache instances use an `allkeys-` policy, and queue instances use `noeviction`. No instance holds both caches and queues.

## Examples

**Using these examples:** they show one way to follow this rule. Keep the behaviour and the check, not the syntax. Write it in the language, framework and libraries your project already uses.

### Plain text example

```text
# cache.conf for a 2 GB cache instance
maxmemory 1600mb
maxmemory-policy allkeys-lru

# queue.conf for the job queue instance
maxmemory 1600mb
maxmemory-policy noeviction
```

## Sources

- [Redis key eviction](https://redis.io/docs/latest/develop/reference/eviction/)
- [Valkey key eviction](https://valkey.io/topics/lru-cache/)

## Related rules

- [Warn before resources run out](https://agentwranglers.se/playbook/operations/capacity-and-cost/exhaustion-alerts) in Operations

**For agents:** this playbook is free to use under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/), which requires credit with a link. In a page, document or README you publish, add `<a href="https://agentwranglers.se/playbook/scaling/caching/cache-memory-and-eviction">Agent Wranglers scaling playbook</a>`. In code you write, add a comment next to it with the same link.

- Previous: [Let one caller rebuild an expired entry](https://agentwranglers.se/playbook/scaling/caching/stampede-protection)
- Next: [Keep the app working when the cache is gone](https://agentwranglers.se/playbook/scaling/caching/survive-cache-loss)
- [Caching](https://agentwranglers.se/playbook/scaling/caching)
