mirror of
https://github.com/long2ice/fastapi-cache.git
synced 2026-03-24 20:47:54 +00:00
28 lines
619 B
Python
28 lines
619 B
Python
class FastAPICache:
|
|
_backend = None
|
|
_prefix = None
|
|
_expire = None
|
|
_init = False
|
|
|
|
@classmethod
|
|
def init(cls, backend, prefix: str = "", expire: int = None):
|
|
if cls._init:
|
|
return
|
|
cls._init = True
|
|
cls._backend = backend
|
|
cls._prefix = prefix
|
|
cls._expire = expire
|
|
|
|
@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
|
|
|
|
@classmethod
|
|
def get_expire(cls):
|
|
return cls._expire
|