mirror of
https://github.com/long2ice/fastapi-cache.git
synced 2026-03-25 04:57:54 +00:00
feat: support cache JSONResponse
This commit is contained in:
@@ -6,6 +6,7 @@ from typing import Any, Dict, Union
|
|||||||
|
|
||||||
import pendulum
|
import pendulum
|
||||||
from fastapi.encoders import jsonable_encoder
|
from fastapi.encoders import jsonable_encoder
|
||||||
|
from starlette.responses import JSONResponse
|
||||||
from starlette.templating import _TemplateResponse as TemplateResponse
|
from starlette.templating import _TemplateResponse as TemplateResponse
|
||||||
|
|
||||||
CONVERTERS = {
|
CONVERTERS = {
|
||||||
@@ -51,6 +52,8 @@ class Coder:
|
|||||||
class JsonCoder(Coder):
|
class JsonCoder(Coder):
|
||||||
@classmethod
|
@classmethod
|
||||||
def encode(cls, value: Any) -> str:
|
def encode(cls, value: Any) -> str:
|
||||||
|
if isinstance(value, JSONResponse):
|
||||||
|
return value.body
|
||||||
return json.dumps(value, cls=JsonEncoder)
|
return json.dumps(value, cls=JsonEncoder)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|||||||
Reference in New Issue
Block a user