fast-twitch.middlewares.cache-policy
Complete generated reference for fast-twitch.middlewares.cache-policy
Usage and execution boundary
Adds cache header policies without replacing existing headers. Its LRU/TTL backend memoizes policy maps, not response bodies. A native stream cannot be reused merely because its policy was cached.
(ns application.middleware
(:require [fast-twitch.middlewares.cache-policy :as middleware]))
(defn handler [_]
{:status 200 :headers {"content-type" "text/plain"} :body "Hello"})
(def app (middleware/wrap-cache-policy handler {:max-age 3600 :immutable? false}))
This defines the Ring handler portion. Adapt app through routing/ft-handler or pass it to server/listen!; startup instructions and a complete walkthrough show the surrounding project.
Settings and defaults
| Setting | Meaning |
|---|---|
:static-prefixes |
Default /static/, /assets/, /favicon |
:max-age |
Default 31536000 for static policy |
:immutable? |
Enabled unless false |
:dynamic-policy |
Default no-cache/no-store map; may be supplied as policy function |
:static-policy |
Custom map/function |
:cacheable? |
Predicate [request options] |
:etag-fn |
Function [request] |
:key-fn |
Function [request options] |
:backend / :max-entries |
Policy memoization backend / default LRU capacity 256 |
Wrapper order and all middleware families. The function reference below preserves the upstream signatures and source links; helper functions do not all share the wrapper's arity.
Upstream function reference
Applies configurable HTTP cache policy headers with @std/cache-backed memoization.
LruCache
The @std/cache LruCache constructor used by the default policy backend. Source
TtlCache
The @std/cache TtlCache constructor available for custom policy backends. Source
cache-policy
(cache-policy request options)
Function.
Returns cache policy headers for the request, using the configured backend. Source
cache-policy-key
(cache-policy-key request options)
Function.
Builds the backend key used for memoizing cache policy headers. Source
cache-policy-response
(cache-policy-response response request options)
Function.
Adds cache policy headers to a response without replacing existing headers. Source
cacheable-request?
(cacheable-request? request)
(cacheable-request? request options)
Function.
Returns true when the request should receive a static cache policy. Source
default-dynamic-policy
The default cache policy for non-static responses. Source
default-static-prefixes
The default URI prefixes treated as static cacheable assets. Source
dynamic-cache-policy
(dynamic-cache-policy _request options)
Function.
Builds the cache policy used for non-static responses. Source
lru-cache-backend
(lru-cache-backend)
(lru-cache-backend max-size)
Function.
Creates an @std/cache LRU backend for memoized cache policy headers. Source
static-cache-policy
(static-cache-policy request options)
Function.
Builds the cache policy used for static cacheable assets. Source
ttl-cache-backend
(ttl-cache-backend ttl-ms)
Function.
Creates an @std/cache TTL backend for memoized cache policy headers. Source
wrap-cache-policy
(wrap-cache-policy handler)
(wrap-cache-policy handler options)
Function.
Wraps a handler so responses receive configurable cache policy headers. Source