HTTP Cache¶
Collect metrics based on prometheus.
- class blacksmith.middleware._async.http_cache.AsyncAbstractCache¶
- Abstract Redis Client. - abstractmethod async initialize() None¶
- Initialize the cache 
 - abstractmethod async get(key: str) str | None¶
- Get a value from redis 
 - abstractmethod async set(key: str, val: str, ex: timedelta) None¶
- Get a value from redis 
 
- class blacksmith.middleware._async.http_cache.AsyncHTTPCacheMiddleware(cache: ~blacksmith.middleware._async.http_cache.AsyncAbstractCache, metrics: ~blacksmith.domain.model.middleware.prometheus.PrometheusMetrics | None = None, policy: ~blacksmith.domain.model.middleware.http_cache.AbstractCachePolicy = <blacksmith.domain.model.middleware.http_cache.CacheControlPolicy object>, serializer: type[~blacksmith.domain.model.middleware.http_cache.AbstractSerializer] = <class 'blacksmith.domain.model.middleware.http_cache.JsonSerializer'>)¶
- Http Cache Middleware based on Cache-Control and redis. - __init__(cache: ~blacksmith.middleware._async.http_cache.AsyncAbstractCache, metrics: ~blacksmith.domain.model.middleware.prometheus.PrometheusMetrics | None = None, policy: ~blacksmith.domain.model.middleware.http_cache.AbstractCachePolicy = <blacksmith.domain.model.middleware.http_cache.CacheControlPolicy object>, serializer: type[~blacksmith.domain.model.middleware.http_cache.AbstractSerializer] = <class 'blacksmith.domain.model.middleware.http_cache.JsonSerializer'>) None¶
 - async initialize() None¶
- Asynchronous initialization of a middleware. - For instance, used to initialize connection to storage backend. 
 - async cache_response(client_name: str, path: str, req: HTTPRequest, resp: HTTPResponse) bool¶
 - async get_from_cache(client_name: str, path: str, req: HTTPRequest) HTTPResponse | None¶
 - __call__(next: AsyncMiddleware) AsyncMiddleware¶
- Call self as a function. 
 - observe_cache_hit(client_name: str, method: str, path: str, status_code: int, latency: float) None¶
 - inc_cache_miss(client_name: str, cachable_state: Literal['uncachable_request', 'uncachable_response', 'cached'], method: Literal['HEAD', 'GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'], path: str, status_code: int) None¶