Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / common / extensions / docs / server2 / object_store.py
blobf33aa913ff5999deb35f644ca3188fc57ce6c56c
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
10 self._key = key
12 def Get(self):
13 return self._future.Get().get(self._key)
15 class ObjectStore(object):
16 '''A class for caching picklable objects.
17 '''
18 def Get(self, key):
19 '''Gets a |Future| with the value of |key| in the object store, or None
20 if |key| is not in the object store.
21 '''
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.
27 '''
28 raise NotImplementedError(self.__class__)
30 def Set(self, key, value):
31 '''Sets key -> value in the object store.
32 '''
33 self.SetMulti({ key: value })
35 def SetMulti(self, items):
36 '''Atomically sets the mapping of keys to values in the object store.
37 '''
38 raise NotImplementedError(self.__class__)
40 def Del(self, key):
41 '''Deletes a key from the object store.
42 '''
43 self.DelMulti([key])
45 def DelMulti(self, keys):
46 '''Deletes |keys| from the object store.
47 '''
48 raise NotImplementedError(self.__class__)