alti3/litestar-skills/litestar-caching
Claude Code and agent skill by alti3/litestar-skills
- community
Checking that the SKILL.md file is still in the repository.
Configure Litestar response caching with route-level `cache` controls, app-level `ResponseCacheConfig`, store selection, TTL strategy, cache key design, and `cache_response_filter` rules. Use when optimizing read-heavy or polling-heavy Litestar endpoints without breaking correctness for tenant-, locale-, or auth-scoped responses. Do not use for write-heavy or immediately consistent workflows unless cache invalidation or versioning is designed explicitly.
Install
npx vskill@latest install alti3/litestar-skills/litestar-cachingSKILL.md
The same SKILL.md was published earlier as alti3/litestar-skills/litestar-caching.
Caching
Execution Workflow
- Identify handlers whose responses are deterministic, expensive, and safe to replay.
- Choose the route-level cache mode:
cache=True, an explicit TTL in seconds, orCACHE_FOREVER. - Set app-level
ResponseCacheConfigfordefault_expiration, store selection, and global key/filter behavior. - Design cache keys around every dimension that changes the payload: path, query params, method, tenant, locale, auth scope, feature flags, or headers.
- Decide how stale data is controlled for mutable resources: short TTL, explicit delete, or versioned keys.
- Verify hits, misses, and stale-data behavior with tests before treating the cache as production-safe.
Core Rules
- Cache only responses that are safe to reuse for another equivalent request.
- Prefer short, explicit TTLs for mutable data.
- Treat
cache=Trueas "useResponseCacheConfig.default_expiration", not as "cache forever." - Use
CACHE_FOREVERonly for truly immutable or explicitly versioned resources. - Never cache personalized or permission-scoped responses unless the cache key fully partitions that context.
- Keep key builders deterministic and stable across processes.
- Use
cache_response_filterto control which responses are written to cache after the status code is known. - Do not assume Litestar provides automatic write-side invalidation for your domain objects; design it deliberately.
Decision Guide
- Use
cache=Truewhen the app-wide default TTL is correct for the route. - Use
cache=<seconds>when a route needs a specific freshness window. - Use
CACHE_FOREVERwhen the payload is immutable, content-addressed, or versioned externally. - Use app-level
ResponseCacheConfigfor baseline TTL, default key builder, named store selection, and response-write filtering. - Use route-level
cache_key_builder=when one handler needs extra key dimensions without changing the whole app. - Keep the default key builder when the response varies only by method, path, and query params.
- Override the key builder when the response varies by headers, tenant, locale, auth identity, or feature flags.
- Use a distributed store such as Redis when multiple app instances must share cache state.
Reference Files
Read only the sections you need:
- For route-level
cachemodes,ResponseCacheConfig, default expiration, and store wiring, read references/route-and-config-patterns.md. - For custom cache key builders, tenant/user safety, and invalidation/versioning strategy, read references/key-builder-and-invalidation.md.
- For
cache_response_filterexamples and test patterns that prove cache correctness, read references/filter-and-testing-patterns.md.
Recommended Defaults
- Start with
cache=Trueplus an explicit app-leveldefault_expiration. - Keep the default
MemoryStoreonly for single-process or low-stakes cases. - Move to a named shared store for horizontally scaled deployments.
- Include every response-shaping input in the cache key before enabling caching on auth-, locale-, or tenant-sensitive routes.
- Cache successful
GETresponses by default; be conservative with anything else. - Prefer short TTLs over complex invalidation when freshness requirements allow it.
Anti-Patterns
- Caching mutation endpoints or non-idempotent workflows.
- Using
cache=Truewithout noticing thatdefault_expiration=Nonemakes the entry indefinite. - Reusing the default key builder on endpoints whose response varies by headers, cookies, auth, or tenant.
- Caching permission-gated responses without identity or scope in the key.
- Assuming a shared cache while still using per-process memory storage in a multi-instance deployment.
- Using
CACHE_FOREVERfor mutable business data without explicit invalidation or versioning. - Treating
cache_response_filteras a substitute for good key design.
Validation Checklist
- Confirm the route is deterministic for the chosen cache key.
- Confirm TTL or forever-caching semantics match product freshness requirements.
- Confirm the configured store is shared or local by intent.
- Confirm the key builder covers all inputs that can change the payload.
- Confirm
cache_response_filterallows and rejects the expected status codes and methods. - Confirm cache hits occur on equivalent requests and miss on materially different ones.
- Confirm stale-data behavior is acceptable after writes, deployments, and worker restarts.
- Confirm tests cover both correctness and isolation for tenant-, locale-, or auth-scoped data.
Cross-Skill Handoffs
- Use
litestar-storesfor backend store lifecycle, namespacing, and TTL policy beyond response caching. - Use
litestar-testingto lock down cache hits, misses, and stale-data boundaries. - Use
litestar-securityorlitestar-authenticationwhen response visibility depends on user identity or permissions. - Use
litestar-responseswhen response metadata or specialized response containers affect what is safe to cache.
Litestar References
- https://docs.litestar.dev/2/usage/caching.html
- https://docs.litestar.dev/2/reference/config.html#litestar.config.response_cache.ResponseCacheConfig
- https://docs.litestar.dev/2/reference/config.html#litestar.config.response_cache.default_cache_key_builder
Security
- Security scanPassed, 90 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingplugins/litestar/skills/litestar-caching/SKILL.md
Popularity
- 7-day trend score
- 0
Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/alti3/litestar-skills/litestar-caching)