object_store.py revision ca12bfac764ba476d6cd062bf1dde12cc64c3f40
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 5from future import Future 6 7class _SingleGetFuture(object): 8 def __init__(self, multi_get, key): 9 self._future = multi_get 10 self._key = key 11 12 def Get(self): 13 return self._future.Get().get(self._key) 14 15class 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)) 23 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__) 29 30 def Set(self, key, value): 31 '''Sets key -> value in the object store. 32 ''' 33 self.SetMulti({ key: value }) 34 35 def SetMulti(self, items): 36 '''Atomically sets the mapping of keys to values in the object store. 37 ''' 38 raise NotImplementedError(self.__class__) 39 40 def Del(self, key): 41 '''Deletes a key from the object store. 42 ''' 43 self.DelMulti([key]) 44 45 def DelMulti(self, keys): 46 '''Deletes |keys| from the object store. 47 ''' 48 raise NotImplementedError(self.__class__) 49