Overview
Cache management endpoints provide visibility into Redis cache performance, hit/miss rates, and memory usage. These endpoints help optimize caching strategies and diagnose performance issues.GET /api/v1/cache/stats
Get cache statistics for all categories.Request
Response
Operation success indicator
Cache statistics grouped by category
Cache Categories
Common cache categories tracked by NeuraTrade:- market_data - Ticker prices, trading pairs, market summaries
- funding_rates - Futures funding rate data
- exchanges - Exchange configuration and capabilities
- orderbook - Order book snapshots
- technical_analysis - Indicator calculations (RSI, MACD, etc.)
- overall - Aggregated stats across all categories
Example Response
GET /api/v1/cache/stats/:category
Get cache statistics for a specific category.Request
Path Parameters
Cache category name (e.g.,
market_data, funding_rates, exchanges)Response
Operation success indicator
Cache statistics for the requested category
Error Responses
- 400 Bad Request: Category parameter is missing
Example Response
GET /api/v1/cache/metrics
Get comprehensive cache metrics including Redis server information.Request
Response
Operation success indicator
Comprehensive cache metrics
Error Responses
- 500 Internal Server Error: Failed to retrieve cache metrics from Redis
This endpoint performs multiple Redis operations (INFO, MEMORY USAGE, CLIENT LIST, DBSIZE) and may take longer to respond than simple stats endpoints.
Example Response
POST /api/v1/cache/stats/reset
Admin Only - Reset all cache statistics to zero.Request
Response
Operation success indicator
Success message
Example Response
POST /api/v1/cache/hit
Testing Only - Manually record cache hits for testing purposes.Request
Query Parameters
Cache category name
Number of hits to record (default: 1)
Response
Operation success indicator
Success message
Number of hits recorded
Error Responses
- 400 Bad Request: Category parameter is missing
Example Response
POST /api/v1/cache/miss
Testing Only - Manually record cache misses for testing purposes.Request
Query Parameters
Cache category name
Number of misses to record (default: 1)
Response
Operation success indicator
Success message
Number of misses recorded
Error Responses
- 400 Bad Request: Category parameter is missing
Example Response
The
/cache/hit and /cache/miss endpoints are intended for testing and development. They allow simulation of cache behavior without triggering actual cache operations.Cache Analytics Strategy
Automatic Tracking
The cache analytics service automatically tracks hit/miss rates when:- Market data is fetched from Redis cache
- Funding rate queries check the cache
- Exchange configuration is retrieved
- Technical indicator results are cached
Performance Optimization
Recommended cache hit rate targets:- Market Data: > 90% (data changes frequently but is queried more often)
- Funding Rates: > 85% (updates every 8 hours for most exchanges)
- Exchange Config: > 95% (rarely changes, heavily cached)
- Order Books: > 70% (high volatility, shorter TTL)
TTL Configuration
Default cache TTL by category:- exchange:config: 1 hour
- exchange:supported: 30 minutes
- market:ticker: 5 seconds
- market:funding: 5 minutes
- cache:analytics:stats: 24 hours (self-reporting)
Monitoring Best Practices
- Track Hit Rates: Monitor
/api/v1/cache/statsto identify categories with low hit rates - Memory Usage: Use
/api/v1/cache/metricsto watch Redis memory consumption - Key Count Growth: Alert on unexpected key count increases (potential memory leak)
- Client Connections: Monitor
connected_clientsto detect connection leaks
Source Reference
Cache endpoints are implemented in:- Handler:
services/backend-api/internal/api/handlers/cache.go:48-231 - Service:
services/backend-api/internal/services/cache_analytics.go:15-343 - Route Registration:
services/backend-api/internal/api/routes.go:1163-1171