mirror of
https://github.com/long2ice/fastapi-cache.git
synced 2026-03-24 20:47:54 +00:00
Make backends store bytes instead of strings
This is, for the majority of backends, the native format anyway, and so we save encoding and decoding when using the PickleCodec or if (in future) a orjson Coder was to be added. For the JsonCodec, the only thing that changed is the location where the JSON data is encoded to bytes and decoded back again to a string.
This commit is contained in:
@@ -36,7 +36,7 @@ class PDItem(BaseModel):
|
||||
)
|
||||
def test_pickle_coder(value: Any) -> None:
|
||||
encoded_value = PickleCoder.encode(value)
|
||||
assert isinstance(encoded_value, str)
|
||||
assert isinstance(encoded_value, bytes)
|
||||
decoded_value = PickleCoder.decode(encoded_value)
|
||||
assert decoded_value == value
|
||||
|
||||
@@ -55,12 +55,12 @@ def test_pickle_coder(value: Any) -> None:
|
||||
)
|
||||
def test_json_coder(value: Any, return_type) -> None:
|
||||
encoded_value = JsonCoder.encode(value)
|
||||
assert isinstance(encoded_value, str)
|
||||
assert isinstance(encoded_value, bytes)
|
||||
decoded_value = JsonCoder.decode_as_type(encoded_value, type_=return_type)
|
||||
assert decoded_value == value
|
||||
|
||||
|
||||
def test_json_coder_validation_error() -> None:
|
||||
invalid = '{"name": "incomplete"}'
|
||||
invalid = b'{"name": "incomplete"}'
|
||||
with pytest.raises(ValidationError):
|
||||
JsonCoder.decode_as_type(invalid, type_=PDItem)
|
||||
|
||||
Reference in New Issue
Block a user