Mercurial > libervia-backend
comparison sat/memory/persistent.py @ 3234:78fea49735c5
core (memory/persistent): added `aset` method in LazyPersistentBinaryDict:
this method does the same as `force` but is there to be consistent with PersistentDict.
`force` should be removed in the future.
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 27 Mar 2020 09:53:00 +0100 |
parents | 843a9279fb5a |
children | 1af840e84af7 |
comparison
equal
deleted
inserted
replaced
3233:8770397f8f82 | 3234:78fea49735c5 |
---|---|
25 | 25 |
26 class MemoryNotInitializedError(Exception): | 26 class MemoryNotInitializedError(Exception): |
27 pass | 27 pass |
28 | 28 |
29 | 29 |
30 class PersistentDict(object): | 30 class PersistentDict: |
31 r"""A dictionary which save persistently each value assigned | 31 r"""A dictionary which save persistently each value assigned |
32 | 32 |
33 /!\ be careful, each assignment means a database write | 33 /!\ be careful, each assignment means a database write |
34 /!\ Memory must be initialised before loading/setting value with instances of this class""" | 34 /!\ Memory must be initialised before loading/setting value with instances of this class""" |
35 storage = None | 35 storage = None |
248 def get(self, key, default=None): | 248 def get(self, key, default=None): |
249 d = self.__getitem__(key) | 249 d = self.__getitem__(key) |
250 d.addErrback(self._defaultOrException, default=default) | 250 d.addErrback(self._defaultOrException, default=default) |
251 return d | 251 return d |
252 | 252 |
253 def aset(self, key, value): | |
254 """Async set, return a Deferred fired when value is actually stored""" | |
255 # FIXME: redundant with force, force must be removed | |
256 # XXX: similar as PersistentDict.aset, but doesn't use cache | |
257 return self.storage.setPrivateValue(self.namespace, key, value, | |
258 self.binary, self.profile) | |
259 | |
253 def setdefault(self, key, default): | 260 def setdefault(self, key, default): |
254 raise NotImplementedError | 261 raise NotImplementedError |
255 | 262 |
256 def force(self, name, value): | 263 def force(self, name, value): |
257 """Force saving of an attribute to storage | 264 """Force saving of an attribute to storage |