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
7 class _SingleGetFuture(object):
8 def __init__(self
, multi_get
, key
):
9 self
._future
= multi_get
13 return self
._future
.Get().get(self
._key
)
15 class ObjectStore(object):
16 '''A class for caching picklable objects.
19 '''Gets a |Future| with the value of |key| in the object store, or None
20 if |key| is not in the object store.
22 return Future(delegate
=_SingleGetFuture(self
.GetMulti([key
]), key
))
24 def GetMulti(self
, keys
):
25 '''Gets a |Future| with values mapped to |keys| from the object store, with
26 any keys not in the object store omitted.
28 raise NotImplementedError(self
.__class
__)
30 def Set(self
, key
, value
):
31 '''Sets key -> value in the object store.
33 self
.SetMulti({ key
: value
})
35 def SetMulti(self
, items
):
36 '''Atomically sets the mapping of keys to values in the object store.
38 raise NotImplementedError(self
.__class
__)
41 '''Deletes a key from the object store.
45 def DelMulti(self
, keys
):
46 '''Deletes |keys| from the object store.
48 raise NotImplementedError(self
.__class
__)