Creates custom get_or_set function

This commit is contained in:
Mouse Reeve
2022-01-08 12:59:56 -08:00
parent 2cca9fab2d
commit f2f40cf3b9
2 changed files with 27 additions and 9 deletions

10
bookwyrm/utils/cache.py Normal file
View File

@ -0,0 +1,10 @@
""" Custom handler for caching """
from django.core.cache import cache
def get_or_set(cache_key, function, *args, timeout=None):
"""Django's built-in get_or_set isn't cutting it"""
value = cache.get(cache_key)
if value is None:
cache.set(cache_key, function(*args), timeout=timeout)
return cache.get(cache_key)