What this prompt does
This prompt makes the AI an API performance engineer designing a multi-layer caching strategy for a [framework] API handling [rps] requests per second across [endpoint_count] endpoints. It audits and classifies every endpoint by cacheability, implements application-level caching in [cache_backend], adds HTTP conditional requests, designs event-driven invalidation, sets up CDN caching via [cdn_provider], and builds a monitoring dashboard. Cache keys combine path, query, and relevant headers, with TTLs from [min_ttl] to [max_ttl].
The structure works because aggressive caching is only safe when invalidation is reliable. The event-driven, tag-based invalidation step is the linchpin: when a [model_type] model is created, updated, or deleted, it publishes to [event_bus], and the subscriber purges every affected cache key by tag, including cascade invalidation where updating a parent record clears the child listing caches it appears in. ETag and Last-Modified support lets the API answer with 304 Not Modified and skip the database query entirely, saving bandwidth and compute, while CDN s-maxage plus Surrogate-Key headers extend caching to the edge with targeted purges instead of full flushes. Classifying every endpoint first ensures user-scoped data never lands in a shared cache.
When to use it
- A hot API needs caching layered from the app through to the CDN
- You want to classify endpoints by cacheability before caching anything
- You need event-driven invalidation so caching doesn't serve stale data
- You want conditional requests returning 304 to cut bandwidth
- You're extending caching to the edge with targeted CDN purges
- You want a dashboard tracking hit ratio against
[target_hit_ratio] - You're caching user-scoped responses and must avoid leaking data between users
Example output
Expect a layered strategy: an endpoint-classification table with cache type, TTL, and invalidation trigger per endpoint across [endpoint_count] endpoints, application caching in [cache_backend] with [cache_key_format] keys built from path, query, and relevant headers and TTLs from [min_ttl] to [max_ttl], ETag and Last-Modified handling for 304 responses, an event-driven tag-based invalidation design keyed off [model_type] changes through [event_bus], CDN configuration with Cache-Control, s-maxage, and Surrogate-Key purging, plus a cache-warming job and a monitoring dashboard tracking hit ratio against [target_hit_ratio] with alerts below [alert_threshold]. It's structured as labeled [framework] steps.
Pro tips
- Classify all
[endpoint_count]endpoints first; caching the wrong endpoint serves stale or user-leaked data - Make invalidation event-driven and tag-based — it's what makes caching at
[min_ttl]–[max_ttl]TTLs safe to ship - Include user-scoping headers like
Authorizationin keys for user-specific caches, or you'll leak data between users - Add ETags so the API can return 304 and skip the database query entirely on unchanged content
- Use
s-maxagefor the CDN and Surrogate-Key headers so you can purge targeted content at the edge instead of flushing everything - Handle cascade invalidation: updating a parent record must also purge the child listing caches it appears in