Add in-memory support.

This commit is contained in:
long2ice
2020-10-08 15:10:34 +08:00
parent 800032c46b
commit c0259bc699
8 changed files with 236 additions and 202 deletions

View File

@@ -1,11 +1,17 @@
class FastAPICache:
_backend = None
_prefix = None
_expire = None
_init = False
@classmethod
def init(cls, backend, prefix: str = ""):
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):
@@ -14,5 +20,8 @@ class FastAPICache:
@classmethod
def get_prefix(cls):
assert cls._prefix, "You must call init first!" # nosec: B101
return cls._prefix
@classmethod
def get_expire(cls):
return cls._expire