diff --git a/sat/memory/persistent.py b/sat/memory/persistent.py index b939ae3b..c0425190 100644 --- a/sat/memory/persistent.py +++ b/sat/memory/persistent.py @@ -44,7 +44,7 @@ class PersistentDict(object): if not self.storage: log.error(_("PersistentDict can't be used before memory initialisation")) raise MemoryNotInitializedError - self._cache = None + self._cache = {} self.namespace = namespace self.profile = profile @@ -111,13 +111,19 @@ class PersistentDict(object): return self._cache.__getitem__(key) def __setitem__(self, key, value): - self.storage.setPrivateValue(self.namespace, key, value, self.binary, self.profile) + self.storage.setPrivateValue(self.namespace, key, value, self.binary, + self.profile) return self._cache.__setitem__(key, value) def __delitem__(self, key): self.storage.delPrivateValue(self.namespace, key, self.binary, self.profile) return self._cache.__delitem__(key) + def clear(self): + """Delete all values from this namespace""" + self._cache.clear() + return self.storage.delPrivateNamespace(self.namespace, self.binary, self.profile) + def get(self, key, default=None): return self._cache.get(key, default) @@ -133,7 +139,8 @@ class PersistentDict(object): @return: deferred fired when data is actually saved """ - return self.storage.setPrivateValue(self.namespace, name, self._cache[name], self.binary, self.profile) + return self.storage.setPrivateValue(self.namespace, name, self._cache[name], + self.binary, self.profile) class PersistentBinaryDict(PersistentDict):