Flagsmith / Flagsmith/flagsmith
Migrate in-memory caches to Redis to reduce worker memory growth
- Dominant language
- Python
- Stars
- 6.6k
- Forks
- 567
- Avg merge
- 1d 13h
- Merged PRs (30d)
- 121
Description
## Summary
Several in-process caches (module-level dicts, `LocMemCache` instances) accumulate data within each gunicorn worker and create memory pressure. Moving these to Redis would keep worker memory stable and share cache state across workers.
## Known in-process caches
- `APIUsageCache` / `FeatureEvaluationCache` in `app_analytics/cache.py` — unbounded dicts keyed by `(host, environment_key, labels)`, flushed only on a time interval.
- `environment_document_cache`, `environment_cache`, `environment_segments_cache`, `bad_environments_cache` in `environments/models.py` — if backed by `LocMemCache`, these persist in each worker independently.
## Why
- In-process caches grow per-worker and are never shared, duplicating memory across workers.
- They contribute to monotonic RSS growth over the worker lifetime.
- Redis-backed caches are bounded, shared, and independently evictable.
## Acceptance Criteria
- [ ] Identify all in-process caches currently in use.
- [ ] Migrate them to Redis (or the configured Django cache backend).
Contributor guide
Assessment
This issue has not been assessed yet.