OLD | NEW |
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 from appengine_wrappers import memcache | 5 from appengine_wrappers import memcache |
6 from object_store import ObjectStore, CACHE_TIMEOUT | 6 from object_store import ObjectStore |
7 | 7 |
8 class _AsyncMemcacheGetFuture(object): | 8 class _AsyncMemcacheGetFuture(object): |
9 def __init__(self, rpc): | 9 def __init__(self, rpc): |
10 self._rpc = rpc | 10 self._rpc = rpc |
11 | 11 |
12 def Get(self): | 12 def Get(self): |
13 return self._rpc.get_result() | 13 return self._rpc.get_result() |
14 | 14 |
15 class MemcacheObjectStore(ObjectStore): | 15 class MemcacheObjectStore(ObjectStore): |
16 def __init__(self, namespace): | 16 def __init__(self, namespace): |
17 self._namespace = namespace | 17 self._namespace = namespace |
18 | 18 |
19 def SetMulti(self, mapping, time=CACHE_TIMEOUT): | 19 def SetMulti(self, mapping): |
20 memcache.Client().set_multi_async(mapping, | 20 memcache.Client().set_multi_async(mapping, namespace=self._namespace) |
21 namespace=self._namespace, | |
22 time=time) | |
23 | 21 |
24 def GetMulti(self, keys, time=CACHE_TIMEOUT): | 22 def GetMulti(self, keys): |
25 rpc = memcache.Client().get_multi_async(keys, namespace=self._namespace) | 23 rpc = memcache.Client().get_multi_async(keys, namespace=self._namespace) |
26 return _AsyncMemcacheGetFuture(rpc) | 24 return _AsyncMemcacheGetFuture(rpc) |
27 | 25 |
28 def Delete(self, key): | 26 def DelMulti(self, keys): |
29 memcache.delete(key, namespace=self._namespace) | 27 memcache.delete_multi(keys, namespace=self._namespace) |
OLD | NEW |