Cache
struct Cache[Inner: Handler & Copyable, S: CacheStore & Deinitable]RFC 9111 HTTP cache middleware.
The middleware composes on top of any :class:CacheStore
implementation. The default :class:InMemoryCacheStore is a
bounded FIFO; callers that want stricter LRU eviction or an
external store (Redis / memcached) swap the store without
touching the rest of the chain.
The store lives on the heap (via :class:flare.runtime.Pool)
and the middleware holds the address as an Int; copies of
the middleware therefore share the same store, which matches
the per-worker singleton shape that Logger /
:class:flare.http.Metrics already use. The cell is leaked
at process exit (worker pthreads live the lifetime of the
server, so nothing meaningful to free); a future
ArcPointer upgrade can swap the leak for ref-counting.
Example::
from flare.http.cache import (
Cache,
InMemoryCacheStore,
)
var server = HttpServer(
Cache[MyHandler, InMemoryCacheStore](
inner=MyHandler(),
store=InMemoryCacheStore.with_capacity(1024),
)
)
- Parameters
Inner: The inner handler.S: The cache store; must satisfy the :class:CacheStoretrait.
Implements Copyable, Handler, Movable
- Fields
inner: Inner: The wrapped handler.store_addr: Int: Heap address of the shared :class:CacheStorecell. Allocated in__init__; intentionally leaked at process exit (see struct doc).
comptime BodyType = InlineBodyThe Body impl this handler authors its response with.
__init__
def __init__(out self, var inner: Inner, var store: S) serve
def serve(self, req: Request) -> Response