fix: merge master

This commit is contained in:
vvanglro
2023-01-11 16:43:36 +08:00
2 changed files with 13 additions and 4 deletions

View File

@@ -9,6 +9,7 @@
- Add `py.typed` file and type hints
- Add TestCase
- Fix cache decorate sync function
- Transparently handle backend connection failures.
### 0.2.0

View File

@@ -123,13 +123,18 @@ def cache(
args=args,
kwargs=copy_kwargs,
)
try:
ttl, ret = await backend.get_with_ttl(cache_key)
except ConnectionError:
ttl, ret = 0, None
if not request:
if ret is not None:
return coder.decode(ret)
ret = await ensure_async_func(*args, **kwargs)
try:
await backend.set(cache_key, coder.encode(ret), expire or FastAPICache.get_expire())
except ConnectionError:
pass
return ret
if request.method != "GET":
@@ -148,7 +153,10 @@ def cache(
ret = await ensure_async_func(*args, **kwargs)
try:
await backend.set(cache_key, coder.encode(ret), expire or FastAPICache.get_expire())
except ConnectionError:
pass
return ret
return inner