Caching Prompts
AI prompts for caching from the LearnWithHasan AI Coding Building Blocks (Performance).
Add Basic Caching
Start here. The simplest caching pattern. From the Caching AI Coding Building Block.
Add caching to my [web app / API / mobile backend]. Right now, every request hits the database directly, even for data that rarely changes. I need: - Cache frequently accessed data like [user profiles / product listings / search results] - Set a TTL of [1 hour] so the cache stays fresh - Invalidate the cache when the underlying data is updated - Log cache hits vs misses so I can measure the impact - Use [Redis / in-memory / file-based] caching My stack: [your framework and language here] I'm learning, so explain each part simply.
API Response Caching
For apps that depend on external APIs From the Caching AI Coding Building Block.
My app calls external APIs like [payment gateway / weather service / social media API] and I'm hitting rate limits and adding unnecessary latency. Set up an API response caching layer that: - Caches responses based on the request URL + parameters - Respects the API's Cache-Control headers when available - Falls back to a configurable TTL when no cache headers exist - Serves stale cache if the external API is down (stale-while-revalidate) - Tracks cache hit rate and average response time saved My stack: [your framework and language here] I'm learning, so explain each part simply.
Full Caching Strategy
For apps that need to handle high traffic From the Caching AI Coding Building Block.
Design a multi-layer caching strategy for my app. I have performance issues at scale and need caching at multiple levels: 1. Database query caching, for repeated queries 2. Page/fragment caching, for rendered HTML or component output 3. CDN caching, for static assets and public pages Requirements: - Each layer should have independent TTL and invalidation - Cache warming on deploy for critical paths - A simple way to flush specific caches when content updates - Monitoring: hit rate, memory usage, stale serves My app: [describe your app and stack] I'm learning, so explain each part simply.