cache_middleware
Cache middleware.
Recommended to be placed before response deserialization middlewares.
Example:
cache = MemoryCache()
cache_middleware(cache, [
(lambda inv: inv.invoker.__name__ == "get_lol_v1_champion", 3600),
(lambda inv: inv.invoker.__name__ ..., float("inf")), # cache indefinitely.
(lambda inv: inv.url ..., 3600),
(lambda inv: inv.params ..., 3600),
])
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cache
|
BaseCache
|
Cache instance. |
required |
rules
|
list[tuple[Callable[[Invocation], bool], float]]
|
Cache rules, defined by a list of (condition, ttl). |
required |