| 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 import logging | 5 import logging |
| 6 | 6 |
| 7 from appengine_wrappers import memcache | 7 from appengine_wrappers import memcache |
| 8 from object_store import ObjectStore | 8 from object_store import ObjectStore |
| 9 | 9 |
| 10 class _AsyncMemcacheGetFuture(object): | 10 class _AsyncMemcacheGetFuture(object): |
| 11 def __init__(self, rpc): | 11 def __init__(self, rpc): |
| 12 self._rpc = rpc | 12 self._rpc = rpc |
| 13 | 13 |
| 14 def Get(self): | 14 def Get(self): |
| 15 return self._rpc.get_result() | 15 return self._rpc.get_result() |
| 16 | 16 |
| 17 class MemcacheObjectStore(ObjectStore): | 17 class MemcacheObjectStore(ObjectStore): |
| 18 def __init__(self, namespace): | 18 def __init__(self, namespace): |
| 19 self._namespace = namespace | 19 self._namespace = namespace |
| 20 | 20 |
| 21 def SetMulti(self, mapping): | 21 def SetMulti(self, mapping): |
| 22 # talking_alarm_clock always fails because the zip is too big. |
| 23 # TODO(kalman): store example zips in blobstore. |
| 24 if any(key.find('talking_alarm_clock') != -1 for key in mapping.iterkeys()): |
| 25 return |
| 22 try: | 26 try: |
| 23 memcache.Client().set_multi_async(mapping, namespace=self._namespace) | 27 memcache.Client().set_multi_async(mapping, namespace=self._namespace) |
| 24 except ValueError as e: | 28 except ValueError as e: |
| 25 logging.error('Caught "ValueError: %s" when mapping keys %s' % ( | 29 logging.error('Caught "ValueError: %s" when mapping keys %s' % ( |
| 26 e, mapping.keys())) | 30 e, mapping.keys())) |
| 27 | 31 |
| 28 def GetMulti(self, keys): | 32 def GetMulti(self, keys): |
| 29 rpc = memcache.Client().get_multi_async(keys, namespace=self._namespace) | 33 rpc = memcache.Client().get_multi_async(keys, namespace=self._namespace) |
| 30 return _AsyncMemcacheGetFuture(rpc) | 34 return _AsyncMemcacheGetFuture(rpc) |
| 31 | 35 |
| 32 def DelMulti(self, keys): | 36 def DelMulti(self, keys): |
| 33 memcache.delete_multi(keys, namespace=self._namespace) | 37 memcache.delete_multi(keys, namespace=self._namespace) |
| OLD | NEW |