Module

cache.middleware

Cache middleware — site-wide GET response caching.

Opt-in viacache_middleware_enabled = Truein config. Only caches GET requests that return 200 with no Set-Cookie header.

Classes

CacheMiddleware 2
Site-wide cache for GET 200 responses. Skips caching for: - Non-GET requests - Non-200 responses -…

Site-wide cache for GET 200 responses.

Skips caching for:

  • Non-GET requests
  • Non-200 responses
  • Responses with Set-Cookie header
  • Streaming/SSE responses

Methods

Internal Methods 2
__init__ 3
def __init__(self, backend, ttl: int = 300, key_func = None) -> None
Parameters
Name Type Description
backend
ttl Default:300
key_func Default:None
__call__ 2 AnyResponse
async
async def __call__(self, request: Request, next: Next) -> AnyResponse
Parameters
Name Type Description
request
next
Returns
AnyResponse