Cursor prompt
Add Redis Caching Layer
Cache-aside Redis caching with typed get/set helpers, TTL management, pattern-based invalidation, and monitoring.
Add a Redis caching layer to {{project_name}} for {{cache_targets}}. ## Cache Pattern: Cache-Aside (read-through on miss) ### Cache Client (lib/cache.ts) ```typescript const redis = new Redis(process.env.REDIS_URL!); export async function get<T>(key: string): Promise<T | null> { const value = await redis.get(key); return value ? (JSON.parse(value) as T) : null; } export async function set(key: string, value: unknown, ttlSeconds: number): Promise<void> { await redis.set(key, JSON.stringify(value), 'EX', ttlSeconds); } export async function del(...keys: string[]): Promise<void> { if (keys.length) await redis.del(keys); } export async function invalidatePattern(pattern: string): Promise<void> { const keys = await redis.keys(pattern); if (keys.length) await redis.del(keys); } ``` Wrap ALL operations in try/catch — cache failures must never break the app. Fail silently and log. ### cached() Helper ```typescript async function cached<T>(key: string, ttl: number, fetcher: () => Promise<T>): Promise<T> { const hit = await get<T>(key); if (hit !== null) return hit; const value = await fetcher(); await set(key, value, ttl); return value; } ``` ### Key Naming Convention {{key_prefix}}:{entity}:{id} for single records {{key_prefix}}:{entity}:list:{hash_of_filters} for lists ### Invalidation on Mutation On create/update/delete of {{cache_targets}}: call del() with the affected keys. ### Monitoring Track cache hit/miss ratio. Log when Redis is unavailable. Alert if Redis memory > 80%. ### Output Cache client, cached() helper, invalidation patterns, and updated API routes.
Fill in: {{project_name}}, {{cache_targets}}, {{key_prefix}}. In Loopy you fill these in a form and copy the finished prompt in one click.
More coding prompts
- CursorAdd File Upload with Cloud StorageMulti-file upload with type checking, size limits, virus scanning, cloud storage, and progress tracking.
- CursorAdd Stripe Payment IntegrationComplete Stripe checkout, webhooks, subscription management, and billing portal with idempotent webhook handling.
- LovableBooking and Scheduling SystemCalendar-based booking with availability management, confirmations, reminders, and payment collection.
- CursorBuild Admin Dashboard with CRUDData table with server-side CRUD, column sorting and filtering, bulk actions, and role-protected admin panel.
- CursorBuild Data Export FeatureExport large datasets to CSV or Excel with streaming for memory efficiency, background jobs, and signed download links.
- CursorBuild Feature from SpecComprehensive prompt for your coding agent to build a complete feature from a technical specification. Handles file creation, imports, and testing.

