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
3 # found in the LICENSE file.
5 from future
import Future
8 class ObjectStore(object):
9 '''A class for caching picklable objects.
12 '''Gets a |Future| with the value of |key| in the object store, or None
13 if |key| is not in the object store.
15 return self
.GetMulti((key
,)).Then(lambda keys
: keys
.get(key
))
17 def GetMulti(self
, keys
):
18 '''Gets a |Future| with values mapped to |keys| from the object store, with
19 any keys not in the object store omitted.
21 raise NotImplementedError(self
.__class
__)
23 def Set(self
, key
, value
):
24 '''Sets key -> value in the object store. Returns a |Future| which is
25 resolved once the key's new value has been stored.
27 return self
.SetMulti({ key
: value
})
29 def SetMulti(self
, items
):
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.
33 raise NotImplementedError(self
.__class
__)
36 '''Deletes a key from the object store.
40 def DelMulti(self
, keys
):
41 '''Deletes |keys| from the object store.
43 raise NotImplementedError(self
.__class
__)