sbt-idp/cope2n-api/fwd_api/utils/cache.py
2024-03-06 15:09:29 +07:00

18 lines
469 B
Python

from fwd_api.models import Caching
def set_cache(key, value):
cache = Caching.objects.filter(key=key)
if cache.count() == 0:
this_cache = Caching(key=key, value=value)
else:
this_cache = cache.first()
this_cache.value = value
this_cache.save()
return this_cache
def get_cache(key):
value = {}
cache = Caching.objects.filter(key=key)
if cache.count() > 0:
value = cache.first().value
return value