plugins/litestar/skills/litestar-stores/SKILL.md
Configure Litestar stores and the store registry for caching, server-side sessions, rate limiting, and other key-value state with explicit backend selection, bytes-safe data handling, TTL and renewal policy, namespacing, registry wiring, and lifecycle cleanup. Use when a Litestar app depends on `MemoryStore`, `FileStore`, `RedisStore`, `ValkeyStore`, or `StoreRegistry`. Do not use for relational persistence, domain repositories, or response-caching policy details that belong in database or caching-focused skills.
npx skillsauth add alti3/litestar-skills litestar-storesInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Use this skill when the problem is Litestar's interchangeable key-value store layer, not relational data modeling.
StoreRegistry, or derived from a namespaced default factory.FileStore expiry cleanup and Redis client ownership.delete_all().MemoryStore for simple single-process caching or low-stakes ephemeral state with minimal overhead.FileStore when persistence on disk matters more than speed, especially for larger or longer-lived data.RedisStore for general production-grade shared state, multi-worker communication, and namespaced bulk operations.ValkeyStore when you want Redis-style behavior on Valkey; Litestar documents it as equivalent in practice to Redis for these store concerns.stores={...} mappings when integrations must resolve known store names.StoreRegistry(default_factory=...) when undefined store names should be created lazily from one policy.with_namespace() when one underlying backend should safely host multiple isolated logical stores.litestar-caching alongside this skill when response-cache TTL, cache keys, or cache filtering are the main design problem.Read only the sections you need:
StoreRegistry, namespacing, integration wiring, and default-factory patterns, read references/registry-and-namespacing.md.Litestar store operations center around a small async API:
set(key, value, expires_in=...)get(key, renew_for=...)delete(key)delete_all()exists(key)expires_in(key)Key behavioral rules from the docs:
set() also accepts strings for convenience, but get() still returns bytes.expires_in can be set when writing data.renew_for can be passed to get() to extend TTL on access when the backend supports expiry for that key.delete() is called for a missing key, it is a no-op.MemoryStoreFileStoredelete_expired() calls.RedisStoredelete_all().ValkeyStoreRedisStore according to the Litestar docs.expires_in on set() for absolute expiration.renew_for on get() for sliding expiration or access-based renewal, such as sessions or LRU-like behavior.FileStore deletes expired values only when they are accessed or when delete_expired() is run explicitly.MemoryStore and FileStore may retain expired data until access or cleanup; do not treat TTL as equivalent to immediate background deletion on those backends.with_namespace() creates a child store whose operations affect only that namespace and its children.delete_all().RedisStore uses LITESTAR as the default namespace.namespace=None disables Redis namespacing and makes delete_all() unavailable.Litestar.stores exposes the application's StoreRegistry.app.stores.get(name) returns a registered store or creates one via the registry's default_factory.MemoryStore for unknown names.StoreRegistry to change that behavior globally.StoreRegistry.register(name, store, allow_override=False) is the explicit registration path when dynamic creation is not enough.Litestar integrations resolve stores by name through the registry. Important consequences:
response_cache store name unless configured otherwise.sessions store name unless configured otherwise.MemoryStore can technically hold arbitrary Python objects because it stores directly in memory, but Litestar's documented interface does not guarantee that portability.delete_expired() periodically for MemoryStore and especially FileStore when stale entries would otherwise accumulate.FileStore.delete_expired() is a good startup or maintenance task when the directory is long-lived.RedisStore directly around your own Redis client and do not use the helper lifecycle, you are responsible for shutting that client down.RedisStore.with_client(...) or explicit ownership flags when you want Litestar/the store to manage the client lifecycle.MemoryStore only for local development, single-process apps, or low-stakes ephemeral state.MemoryStore object storage.from litestar import Litestar, get
from litestar.config.response_cache import ResponseCacheConfig
from litestar.middleware.rate_limit import RateLimitConfig
from litestar.middleware.session.server_side import ServerSideSessionConfig
from litestar.stores.redis import RedisStore
from litestar.stores.registry import StoreRegistry
root_store = RedisStore.with_client()
@get("/cached", cache=True, sync_to_thread=False)
def cached_handler() -> str:
return "hello"
app = Litestar(
[cached_handler],
stores=StoreRegistry(default_factory=root_store.with_namespace),
response_cache_config=ResponseCacheConfig(store="response_cache"),
middleware=[
ServerSideSessionConfig(store="sessions").middleware,
RateLimitConfig(rate_limit=("second", 10), store="rate_limit").middleware,
],
)
MemoryStore for state that must be shared across workers or processes.MemoryStore happens to allow it.delete_all() without namespaces or isolated store names.FileStore or MemoryStore.namespace=None to Redis and then expecting safe namespace-scoped bulk deletion.app.stores.get(name) resolves the intended store for each integration.MemoryStore.litestar-caching for response-cache TTL, key-builder, and cache-filter strategy.litestar-authentication or litestar-security when session/auth data is the main concern.litestar-middleware when rate limit or session middleware behavior is the primary task.litestar-app-setup for startup/shutdown cleanup hooks around store maintenance.litestar-testing to verify expiry, integration wiring, and multi-backend behavior.development
Build Litestar WebSocket endpoints with low-level websocket handlers, websocket listeners, websocket streams, dependency injection, custom websocket classes, transport-mode control, and graceful connection lifecycle handling. Use when implementing bidirectional real-time communication, reactive websocket message handling, or proactive server push over WebSockets. Do not use for server-side pub/sub fanout that is better expressed with channels alone.
tools
Test Litestar applications with TestClient, AsyncTestClient, create_test_client, websocket test helpers, dependency overrides, mocked dependencies, lifecycle-aware fixtures, and deterministic success and failure assertions. Use when adding or fixing Litestar test coverage, including exception contracts, override precedence, websocket behavior, event-bus side effects, or live-server-only response patterns. Do not use as a substitute for production observability or runtime debugging strategy.
development
Configure Litestar templating with `TemplateConfig`, Jinja/Mako/MiniJinja engines, file-or-string `Template` responses, request and CSRF-aware context, template callables, and custom engine integration. Use when implementing or fixing server-rendered HTML in Litestar. Do not use for static asset serving or pure JSON API endpoints.
development
Serve static assets in Litestar with `create_static_files_router()`, explicit mount paths, HTML mode, cache-control policy, URL reversal, custom file systems, and symlink-safe directory boundaries. Use when exposing JS, CSS, images, downloadable artifacts, or static HTML from controlled directories. Do not use for upload ingestion, user-writable file publication, or arbitrary file-download endpoints that need per-request authorization logic.