Cache Management
The Config Service uses Redis for distributed caching to reduce database load and improve response times. The CacheController at /api/v1/cache provides endpoints for viewing cache statistics, invalidating specific entries, and clearing caches.
Get Cache Statistics
View hit rates, miss rates, and cache size.
Endpoint: GET /api/v1/cache/stats
curl http://localhost:8888/api/v1/cache/stats \
-H "Authorization: Bearer ${TOKEN}"Response:
{
"hitCount": 145230,
"missCount": 12450,
"hitRate": 0.921,
"evictionCount": 340,
"size": 8542,
"maxSize": 10000,
"averageLoadPenalty": "2.3ms"
}Reset Statistics
Reset the cache statistics counters.
Endpoint: POST /api/v1/cache/stats/reset
curl -X POST http://localhost:8888/api/v1/cache/stats/reset \
-H "Authorization: Bearer ${TOKEN}"Clear All Caches
This operation clears all cached configurations and feature flags. The next requests will hit the database directly, which may cause a temporary increase in latency.
Endpoint: DELETE /api/v1/cache/all
curl -X DELETE http://localhost:8888/api/v1/cache/all \
-H "Authorization: Bearer ${TOKEN}"Clear Tenant Config Cache
Invalidate all cached configurations for a specific tenant.
Endpoint: DELETE /api/v1/cache/tenant/{tenantId}/configs
curl -X DELETE http://localhost:8888/api/v1/cache/tenant/550e8400-e29b-41d4-a716-446655440000/configs \
-H "Authorization: Bearer ${TOKEN}"Clear Tenant Flag Cache
Invalidate all cached feature flags for a specific tenant.
Endpoint: DELETE /api/v1/cache/tenant/{tenantId}/flags
curl -X DELETE http://localhost:8888/api/v1/cache/tenant/550e8400-e29b-41d4-a716-446655440000/flags \
-H "Authorization: Bearer ${TOKEN}"Invalidate Specific Config
Endpoint: DELETE /api/v1/cache/config/{tenantId}/{configKey}
curl -X DELETE http://localhost:8888/api/v1/cache/config/550e8400-e29b-41d4-a716-446655440000/query.timeout \
-H "Authorization: Bearer ${TOKEN}"Invalidate Specific Flag
Endpoint: DELETE /api/v1/cache/flag/{tenantId}/{flagKey}
curl -X DELETE http://localhost:8888/api/v1/cache/flag/550e8400-e29b-41d4-a716-446655440000/ai.streaming-responses \
-H "Authorization: Bearer ${TOKEN}"Cache Configuration
config-service:
cache:
ttl: 300s # Cache entries expire after 5 minutes
max-size: 10000 # Maximum number of cached entries
redis:
key-prefix: "config:"
flag-prefix: "flag:"Automatic Invalidation
The cache is automatically invalidated when:
| Event | Cache Cleared |
|---|---|
| Config entry updated | Specific config key for tenant |
| Config entry deleted | Specific config key for tenant |
| Feature flag updated | Specific flag key for tenant |
| Feature flag toggled | Specific flag key for tenant |
| Environment promotion | All configs for tenant in target environment |
| Bulk import | All configs for tenant |