clear cache after each map update
This commit is contained in:
parent
cf1630fd83
commit
be693bee4b
1 changed files with 11 additions and 0 deletions
11
src/c3nav/mapdata/utils/cache/local.py
vendored
11
src/c3nav/mapdata/utils/cache/local.py
vendored
|
@ -2,6 +2,8 @@ from collections import OrderedDict
|
|||
|
||||
from django.core.cache import cache
|
||||
|
||||
from c3nav.mapdata.models import MapUpdate
|
||||
|
||||
|
||||
class NoneFromCache:
|
||||
pass
|
||||
|
@ -12,7 +14,9 @@ class LocalCacheProxy:
|
|||
# only usable for stuff that never changes, obviously
|
||||
def __init__(self, maxsize=128):
|
||||
self._maxsize = maxsize
|
||||
self._mapupdate = None
|
||||
self._items = OrderedDict()
|
||||
self._check_mapupdate()
|
||||
|
||||
def get(self, key, default=None):
|
||||
print('get')
|
||||
|
@ -36,7 +40,14 @@ class LocalCacheProxy:
|
|||
while len(self._items) > self._maxsize:
|
||||
self._items.pop(next(iter(self._items.keys())))
|
||||
|
||||
def _check_mapupdate(self):
|
||||
mapupdate = MapUpdate.current_cache_key()
|
||||
if self._mapupdate != mapupdate:
|
||||
self._items = []
|
||||
self._mapupdate = mapupdate
|
||||
|
||||
def set(self, key, value, expire):
|
||||
self._check_mapupdate()
|
||||
cache.set(key, value, expire)
|
||||
self._items[key] = value
|
||||
self._prune()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue