Replace per-process in-memory cache with Flask-Caching (Redis backend) - #48
Merged
Conversation
- Add Flask-Caching and redis to requirements.txt - Configure Flask-Caching from CACHE_TYPE and CACHE_REDIS_URL env vars - Replace custom _cache dict with Flask-Caching cache object - Add redis service to production docker-compose.yml - Update .env.example and README.md with new config vars - Update all tests to use cache.clear() instead of _cache.clear() Co-authored-by: Jackass4life <94110786+Jackass4life@users.noreply.github.com> Agent-Logs-Url: https://github.com/Jackass4life/Nautobot-maps/sessions/a4c3f513-0056-46da-a185-d09ced34fff2
Copilot
AI
changed the title
[WIP] Fix in-memory cache by adding Redis support
Replace per-process in-memory cache with Flask-Caching (Redis backend)
Mar 24, 2026
Jackass4life
marked this pull request as ready for review
March 24, 2026 10:37
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
SimpleCachevia a plain dict is per-process. With 4 Gunicorn workers each maintains its own cache — 4× API load, inconsistent state across requests.Changes
app.py: Replace_cachedict + manual TTL logic withflask_caching.Cache. Backend configurable viaCACHE_TYPE/CACHE_REDIS_URLenv vars; defaults toSimpleCachefor single-worker/dev use.docker-compose.yml: Addredis:7-alpineservice; wirenautobot-mapsto useRedisCacheby default.requirements.txt: AddFlask-Caching==2.3.1,redis==5.3.0..env.example/README.md: DocumentCACHE_TYPEandCACHE_REDIS_URL._cache.clear()→cache.clear(); rewrite expiry test to use Flask-Caching timeout instead of manipulating internal dict timestamps.Usage
No env vars needed for dev — falls back to
SimpleCacheautomatically.Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.