sbt-idp/cope2n-api/fwd_api/utils/cache.py

18 lines
469 B
Python
Raw Normal View History

2024-03-05 08:39:51 +00:00
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