services papkasi o'chirildi

This commit is contained in:
A'zamov Samandar
2025-04-19 15:18:13 +05:00
parent 291f31b09b
commit eff4606079
124 changed files with 7 additions and 7 deletions

18
auth/core/utils/cache.py Normal file
View File

@@ -0,0 +1,18 @@
import hashlib
from django.core.cache import cache
from config.env import env
class Cache:
def remember(self, func, key: str, timeout=None, *args, **kwargs):
cache_enabled = env.bool("CACHE_ENABLED")
key = hashlib.md5(key.encode("utf-8")).hexdigest()
response = cache.get(key)
if not cache_enabled:
return func(*args, **kwargs)
elif response is None:
response = func(*args, **kwargs)
cache.set(key, response, env.int("CACHE_TIME") if timeout is None else timeout)
return response