Refactor caching logic
This commit is contained in:
parent
4c6109a1d6
commit
01dec1e140
7 changed files with 165 additions and 122 deletions
9
gallery/cache.py
Normal file
9
gallery/cache.py
Normal file
|
@ -0,0 +1,9 @@
|
|||
from django.core.cache import cache
|
||||
|
||||
|
||||
def cached_or_set(key, timeout, func):
|
||||
value = cache.get(key)
|
||||
if value is None:
|
||||
value = func()
|
||||
cache.set(key, value, timeout)
|
||||
return value
|
Loading…
Add table
Add a link
Reference in a new issue