Files
fastapi-cache/fastapi_cache/__init__.py

28 lines
619 B
Python
Raw Normal View History

2020-08-26 18:04:57 +08:00
class FastAPICache:
_backend = None
_prefix = None
2020-10-08 15:10:34 +08:00
_expire = None
_init = False
2020-08-26 18:04:57 +08:00
@classmethod
2020-10-08 15:10:34 +08:00
def init(cls, backend, prefix: str = "", expire: int = None):
if cls._init:
return
cls._init = True
2020-08-26 18:04:57 +08:00
cls._backend = backend
cls._prefix = prefix
2020-10-08 15:10:34 +08:00
cls._expire = expire
2020-08-26 18:04:57 +08:00
@classmethod
def get_backend(cls):
assert cls._backend, "You must call init first!" # nosec: B101
return cls._backend
@classmethod
def get_prefix(cls):
return cls._prefix
2020-10-08 15:10:34 +08:00
@classmethod
def get_expire(cls):
return cls._expire