Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(28)

Side by Side Diff: chrome/common/extensions/docs/server2/memcache_object_store.py

Issue 658733004: Docserver: Make ObjectStore set calls return Futures (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 future import Future
8 from object_store import ObjectStore 9 from object_store import ObjectStore
9 10
10 class _AsyncMemcacheGetFuture(object): 11 class _AsyncMemcacheIOFuture(object):
11 def __init__(self, rpc): 12 def __init__(self, rpc):
12 self._rpc = rpc 13 self._rpc = rpc
13 14
14 def Get(self): 15 def Get(self):
15 return self._rpc.get_result() 16 return self._rpc.get_result()
16 17
17 class MemcacheObjectStore(ObjectStore): 18 class MemcacheObjectStore(ObjectStore):
18 def __init__(self, namespace): 19 def __init__(self, namespace):
19 self._namespace = namespace 20 self._namespace = namespace
20 21
21 def SetMulti(self, mapping): 22 def SetMulti(self, mapping):
22 # talking_alarm_clock always fails because the zip is too big. 23 # talking_alarm_clock always fails because the zip is too big.
23 # TODO(kalman): store example zips in blobstore. 24 # TODO(kalman): store example zips in blobstore.
24 if any(key.find('talking_alarm_clock') != -1 for key in mapping.iterkeys()): 25 if any(key.find('talking_alarm_clock') != -1 for key in mapping.iterkeys()):
25 return 26 return Future(callback=lambda: None)
not at google - send to devlin 2014/10/23 20:00:19 Any reason why this isn't Future(value=None)?
Ken Rockot(use gerrit already) 2014/10/23 20:16:18 Yes. The reason is that I'm bad at Future. Fixed.
26 try: 27 try:
27 memcache.Client().set_multi_async(mapping, namespace=self._namespace) 28 rpc = memcache.Client().set_multi_async(mapping,
29 namespace=self._namespace)
30 return _AsyncMemcacheIOFuture(rpc)
28 except ValueError as e: 31 except ValueError as e:
29 logging.error('Caught "ValueError: %s" when mapping keys %s' % ( 32 logging.error('Caught "ValueError: %s" when mapping keys %s' % (
30 e, mapping.keys())) 33 e, mapping.keys()))
31 34
32 def GetMulti(self, keys): 35 def GetMulti(self, keys):
33 rpc = memcache.Client().get_multi_async(keys, namespace=self._namespace) 36 rpc = memcache.Client().get_multi_async(keys, namespace=self._namespace)
34 return _AsyncMemcacheGetFuture(rpc) 37 return _AsyncMemcacheIOFuture(rpc)
35 38
36 def DelMulti(self, keys): 39 def DelMulti(self, keys):
37 memcache.delete_multi(keys, namespace=self._namespace) 40 memcache.delete_multi(keys, namespace=self._namespace)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698