gold eggs backend
Some checks failed
Build and Push to Docker Hub / build-test-push (push) Failing after 1m55s
Some checks failed
Build and Push to Docker Hub / build-test-push (push) Failing after 1m55s
This commit is contained in:
17
core/utils/cache.py
Executable file
17
core/utils/cache.py
Executable file
@@ -0,0 +1,17 @@
|
||||
import hashlib
|
||||
from django.core.cache import cache
|
||||
|
||||
from common.env import env
|
||||
|
||||
|
||||
class Cache:
|
||||
def remember(self, func, key: str):
|
||||
cache_enabled = env("CACHE_ENABLED")
|
||||
key = hashlib.md5(key.encode("utf-8")).hexdigest()
|
||||
response = cache.get(key)
|
||||
|
||||
if (response is None) or cache_enabled:
|
||||
response = func()
|
||||
cache.set(key, response, env("CACHE_TIME"))
|
||||
|
||||
return response
|
||||
Reference in New Issue
Block a user