Skip to content

feat: add smart caching strategy for dashboard and analytics#967

Open
gavin913427-hash wants to merge 1 commit into
rohitdash08:mainfrom
gavin913427-hash:feat/smart-caching-strategy
Open

feat: add smart caching strategy for dashboard and analytics#967
gavin913427-hash wants to merge 1 commit into
rohitdash08:mainfrom
gavin913427-hash:feat/smart-caching-strategy

Conversation

@gavin913427-hash
Copy link
Copy Markdown

Changes

Implement intelligent caching with TTL strategies and automatic invalidation.

CacheManager Features

  • 5 TTL strategies: realtime (30s), short (5min), medium (30min), long (1hr), static (24hr)
  • get_or_set() for read-through caching with automatic TTL selection
  • invalidate_user() and invalidate_user_type() for targeted cache clearing
  • get_stats() for cache hit/miss/memory monitoring
  • Graceful error handling for Redis failures

Files Modified

  • packages/backend/app/services/cache.py - Enhanced with CacheManager class
  • packages/backend/app/routes/dashboard.py - Uses get_or_set(), added cache-stats endpoint
  • packages/backend/app/routes/expenses.py - Uses invalidate_user_type() for precise invalidation
  • packages/backend/app/services/README_CACHE.md - NEW: Documentation
  • packages/backend/tests/test_cache.py - NEW: 33 tests

Fixes #127

Implement intelligent caching with TTL strategies and automatic invalidation:

- CacheManager class with 5 TTL strategies (realtime/short/medium/long/static)
- get_or_set() for read-through caching with automatic TTL selection
- invalidate_user() and invalidate_user_type() for targeted cache clearing
- get_stats() for cache hit/miss/memory monitoring
- Dashboard summary uses get_or_set() with medium TTL (30min)
- Expenses route uses invalidate_user_type() for precise invalidation
- New GET /dashboard/cache-stats endpoint for monitoring
- 33 tests covering all cache operations
- Documentation (README_CACHE.md)

Fixes rohitdash08#127
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Smart caching strategy for dashboard & analytics

1 participant