Merge branch 'main' into feat/type-hints-covering

# Conflicts:
#	fastapi_cache/coder.py
#	fastapi_cache/decorator.py
This commit is contained in:
Ivan Moiseev
2022-11-03 15:53:22 +04:00
6 changed files with 40 additions and 3 deletions

View File

@@ -6,6 +6,7 @@ from typing import Any, Dict, Union
import pendulum
from fastapi.encoders import jsonable_encoder
from starlette.templating import _TemplateResponse as TemplateResponse
CONVERTERS = {
"date": lambda x: pendulum.parse(x, exact=True),
@@ -60,6 +61,8 @@ class JsonCoder(Coder):
class PickleCoder(Coder):
@classmethod
def encode(cls, value: Any) -> str:
if isinstance(value, TemplateResponse):
value = value.body
return str(pickle.dumps(value))
@classmethod

View File

@@ -97,7 +97,7 @@ def cache(
request: Optional[Request] = copy_kwargs.pop("request", None)
response: Optional[Response] = copy_kwargs.pop("response", None)
if (
request and request.headers.get("Cache-Control") == "no-store"
request and request.headers.get("Cache-Control") in ("no-store", "no-cache")
) or not FastAPICache.get_enable():
return await ensure_async_func(*args, **kwargs)