diff --git a/oml/cache.py b/oml/cache.py index 18010ab..dd0e823 100644 --- a/oml/cache.py +++ b/oml/cache.py @@ -23,3 +23,8 @@ class Cache(dict): if key in self._added: del self._added[key] del self[key] + + def clear(self, prefix): + for key in list(self): + if key.startswith(prefix): + self.delete(key) diff --git a/oml/item/api.py b/oml/item/api.py index c0aa61c..da4507c 100644 --- a/oml/item/api.py +++ b/oml/item/api.py @@ -140,9 +140,7 @@ def edit(data): if len(ids) > 1: response = data response['id'] = edited - for key in list(state.cache): - if key.startswith('group:'): - state.cache.delete(key) + state.cache.clear('group:') return response actions.register(edit, cache=False) diff --git a/oml/user/api.py b/oml/user/api.py index 4578a24..74c44b7 100644 --- a/oml/user/api.py +++ b/oml/user/api.py @@ -233,6 +233,7 @@ def addListItems(data): l = models.List.get_or_create(data['list']) if l: l.add_items(data['items']) + state.cache.clear('group:') return l.json() return {} actions.register(addListItems, cache=False) @@ -248,6 +249,7 @@ def removeListItems(data): l = models.List.get(data['list']) if l: l.remove_items(data['items']) + state.cache.clear('group:') return l.json() return {} actions.register(removeListItems, cache=False)