Skip to content
Back to skills

2723 007 Pluggable Cache Backend 6ee2c5f9

ASecurity

- *Status:* Accepted - *Date:* 2025-02-21 - *Deciders:* Core Engineering Team

  • 9 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added October 11, 2026
testingsqlnodedatabasebackend

Security analysis

A100/100

Scanned October 11, 2026

npx -y skills add tools-only/X-Skills --skill 2723-007-pluggable-cache-backend_6ee2c5f9 --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of 2723 007 Pluggable Cache Backend 6ee2c5f9?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for 2723 007 Pluggable Cache Backend 6ee2c5f9
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/tools-only-2723-007-pluggable-cache-backend-6ee2c5f9/badge)](https://www.skillsdirectory.com/skills/tools-only-2723-007-pluggable-cache-backend-6ee2c5f9)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

SKILL.md
# ADR-0007: Pluggable Cache Backend (memory / Redis / database)

- *Status:* Accepted
- *Date:* 2025-02-21
- *Deciders:* Core Engineering Team

## Context

ContextForge uses short-lived caching for:

- Tool responses and resource lookups
- Peer discovery metadata
- Temporary session state and rate-limiting

Different deployments require different caching characteristics:

- Dev mode: no external services (in-memory only)
- Production: clustered and persistent (Redis)
- Air-gapped: embedded fallback (database table)

The config exposes `CACHE_TYPE=memory|redis|database`.

## Decision

Abstract the caching system via a `CacheBackend` interface and support the following pluggable backends:

- `MemoryCacheBackend`: simple `dict` with TTL, for dev and unit tests
- `RedisCacheBackend`: shared, centralized cache for multi-node clusters
- `DatabaseCacheBackend`: uses SQLAlchemy ORM to persist TTL-based records

Selection is driven by the `CACHE_TYPE` environment variable. Code paths use a consistent interface regardless of backend.

For multi-regional deployments, we support **Redis Cluster** for distributed caching across geographic regions. This enables:

- Cross-region cache replication
- Automatic sharding and failover
- High availability with Sentinel mode
- Shared state for federation across clusters

## Consequences

- 🔄 Easy to switch cache backend per environment or load profile
- 🚀 Redis allows horizontal scaling and persistent shared state
- 🌍 Redis Cluster enables multi-regional deployments with federation
- ❌ Memory cache does not survive restarts or share state
- 🐢 Database cache is slower, but useful in restricted networks

## Alternatives Considered

| Option | Why Not |
|--------|---------|
| **Hardcoded Redis** | Adds operational overhead and single point of failure for dev. |
| **Memory-only cache** | Incompatible with horizontal scale or restart resilience. |
| **External CDN or HTTP cache** | Doesn't address in-process sessions, discovery, or tool state. |
| **Disk-based cache (e.g., shelve, pickle)** | Complex invalidation and concurrency issues; not cloud-ready. |

## Status

All three cache backends are implemented and the gateway selects one dynamically based on configuration.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.