clear cache after each map update
@@ -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()
