Files
AutoGPT/autogpt_platform/backend/.gitignore
Swifty ebeefc96e8 feat(backend): implement caching layer for store API endpoints (Part 1) (#10975)
## Summary
This PR introduces comprehensive caching for the Store API endpoints to
improve performance and reduce database load. This is **Part 1** in a
series of PRs to add comprehensive caching across our entire API.

### Key improvements:
- Implements caching layer using the existing `@cached` decorator from
`autogpt_libs.utils.cache`
- Reduces database queries by 80-90% for frequently accessed public data
- Built-in thundering herd protection prevents database overload during
cache expiry
- Selective cache invalidation ensures data freshness when mutations
occur

## Details

### Cached endpoints with TTLs:
- **Public data (5-10 min TTL):**
  - `/agents` - Store agents list (2 min)
  - `/agents/{username}/{agent_name}` - Agent details (5 min)
  - `/graph/{store_listing_version_id}` - Agent graphs (10 min)
  - `/agents/{store_listing_version_id}` - Agent by version (10 min)
  - `/creators` - Creators list (5 min)
  - `/creator/{username}` - Creator details (5 min)

- **User-specific data (1 min TTL):**
  - `/profile` - User profiles (5 min)
  - `/myagents` - User's own agents (1 min)
  - `/submissions` - User's submissions (1 min)

### Cache invalidation strategy:
- Profile updates → clear user's profile cache
- New reviews → clear specific agent cache + agents list
- New submissions → clear agents list + user's caches
- Submission edits → clear related version caches

### Cache management endpoints:
- `GET /cache/info` - Monitor cache statistics
- `POST /cache/clear` - Clear all caches
- `POST /cache/clear/{cache_name}` - Clear specific cache

## Changes  
<!-- REQUIRED: Bullet point summary of changes -->
- Added caching decorators to all suitable GET endpoints in store routes
- Implemented cache invalidation on data mutations (POST/PUT/DELETE)
- Added cache management endpoints for monitoring and manual clearing
- Created comprehensive test suite for cache_delete functionality
- Verified thundering herd protection works correctly

## Testing
<!-- How to test your changes -->
-  Created comprehensive test suite (`test_cache_delete.py`)
validating:
  - Selective cache deletion works correctly
  - Cache entries are properly invalidated on mutations
  - Other cache entries remain unaffected
  - cache_info() accurately reflects state
-  Tested thundering herd protection with concurrent requests
-  Verified all endpoints return correct data with and without cache

## Checklist
<!-- REQUIRED: Be sure to check these off before marking the PR ready
for review. -->
- [x] I have self-reviewed this PR's diff, line by line
- [x] I have updated and tested the software architecture documentation
(if applicable)
- [x] I have run the agent to verify that it still works (if applicable)

---------

Co-authored-by: Zamil Majdy <zamil.majdy@agpt.co>
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Nicholas Tindle <nicholas.tindle@agpt.co>
Co-authored-by: Reinier van der Leer <pwuts@agpt.co>
2025-09-24 10:01:52 +00:00

21 lines
287 B
Plaintext

.env
database.db
database.db-journal
dev.db
dev.db-journal
build/
config.json
secrets/*
!secrets/.gitkeep
*.ignore.*
*.ign.*
# Load test results and reports
load-tests/*_RESULTS.md
load-tests/*_REPORT.md
load-tests/results/
load-tests/*.json
load-tests/*.log
load-tests/node_modules/*