OLD | NEW |
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 from future import Future | 5 from future import Future |
6 | 6 |
7 | 7 |
8 class ObjectStore(object): | 8 class ObjectStore(object): |
9 '''A class for caching picklable objects. | 9 '''A class for caching picklable objects. |
10 ''' | 10 ''' |
11 def Get(self, key): | 11 def Get(self, key): |
12 '''Gets a |Future| with the value of |key| in the object store, or None | 12 '''Gets a |Future| with the value of |key| in the object store, or None |
13 if |key| is not in the object store. | 13 if |key| is not in the object store. |
14 ''' | 14 ''' |
15 return self.GetMulti((key,)).Then(lambda keys: keys.get(key)) | 15 return self.GetMulti((key,)).Then(lambda keys: keys.get(key)) |
16 | 16 |
17 def GetMulti(self, keys): | 17 def GetMulti(self, keys): |
18 '''Gets a |Future| with values mapped to |keys| from the object store, with | 18 '''Gets a |Future| with values mapped to |keys| from the object store, with |
19 any keys not in the object store omitted. | 19 any keys not in the object store omitted. |
20 ''' | 20 ''' |
21 raise NotImplementedError(self.__class__) | 21 raise NotImplementedError(self.__class__) |
22 | 22 |
23 def Set(self, key, value): | 23 def Set(self, key, value): |
24 '''Sets key -> value in the object store. | 24 '''Sets key -> value in the object store. Returns a |Future| which is |
| 25 resolved once the key's new value has been stored. |
25 ''' | 26 ''' |
26 self.SetMulti({ key: value }) | 27 return self.SetMulti({ key: value }) |
27 | 28 |
28 def SetMulti(self, items): | 29 def SetMulti(self, items): |
29 '''Atomically sets the mapping of keys to values in the object store. | 30 '''Atomically sets the mapping of keys to values in the object store. |
| 31 Returns a |Future| which is resolved once the new mapping has been stored. |
30 ''' | 32 ''' |
31 raise NotImplementedError(self.__class__) | 33 raise NotImplementedError(self.__class__) |
32 | 34 |
33 def Del(self, key): | 35 def Del(self, key): |
34 '''Deletes a key from the object store. | 36 '''Deletes a key from the object store. |
35 ''' | 37 ''' |
36 self.DelMulti([key]) | 38 self.DelMulti([key]) |
37 | 39 |
38 def DelMulti(self, keys): | 40 def DelMulti(self, keys): |
39 '''Deletes |keys| from the object store. | 41 '''Deletes |keys| from the object store. |
40 ''' | 42 ''' |
41 raise NotImplementedError(self.__class__) | 43 raise NotImplementedError(self.__class__) |
OLD | NEW |