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. 4 5 from future import Future 6 7 8 class ObjectStore(object): 9 '''A class for caching picklable objects. 10 ''' 11 def Get(self, key): 12 '''Gets a |Future| with the value of |key| in the object store, or None 13 if |key| is not in the object store. 14 ''' 15 return self.GetMulti((key,)).Then(lambda keys: keys.get(key)) 16 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. 20 ''' 21 raise NotImplementedError(self.__class__) 22 23 def Set(self, key, value): 24 '''Sets key -> value in the object store. 25 ''' 26 self.SetMulti({ key: value }) 27 28 def SetMulti(self, items): 29 '''Atomically sets the mapping of keys to values in the object store. 30 ''' 31 raise NotImplementedError(self.__class__) 32 33 def Del(self, key): 34 '''Deletes a key from the object store. 35 ''' 36 self.DelMulti([key]) 37 38 def DelMulti(self, keys): 39 '''Deletes |keys| from the object store. 40 ''' 41 raise NotImplementedError(self.__class__) 42