Files
fastapi-cache/fastapi_cache/backends/__init__.py
Martijn Pieters d10f4af6d6 Import supported backends
This ensures that any syntax issues are caught early (by type checkers
and tests). Backends that are missing dependencies are skipped. By
importing, this exposed an issue where the redis type annotations
raised an exception, which has been fixed by using forward annotations.

To help avoid import dependency hell, the Backend ABC has been moved to
`fastapi_cache.types`. In the process, it has been made an actual ABC.
2023-05-14 17:02:30 +01:00

30 lines
626 B
Python

from fastapi_cache.types import Backend
from fastapi_cache.backends import inmemory
__all__ = ["Backend", "inmemory"]
# import each backend in turn and add to __all__. This syntax
# is explicitly supported by type checkers, while more dynamic
# syntax would not be recognised.
try:
from fastapi_cache.backends import dynamodb
except ImportError:
pass
else:
__all__ += ["dynamodb"]
try:
from fastapi_cache.backends import memcached
except ImportError:
pass
else:
__all__ += ["memcached"]
try:
from fastapi_cache.backends import redis
except ImportError:
pass
else:
__all__ += ["redis"]