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.
8 from appengine_wrappers
import memcache
9 from future
import Future
10 from object_store
import ObjectStore
13 class MemcacheObjectStore(ObjectStore
):
14 def __init__(self
, namespace
):
15 self
._namespace
= namespace
17 def SetMulti(self
, mapping
):
18 # Some files are too big to fit in memcache, and will throw a ValueError if
19 # we try. That's caught below, but to avoid log spew as much as possible
20 # (and to try to store as many things as possible, since this is Set*Multi*
21 # after all, and there may be other things to store from |mapping|), delete
22 # the paths which we know don't work.
24 # TODO(kalman): Store big things (like example zips) in blobstore so that
25 # this doesn't happen.
26 log_spewers
= ('assets/remote-debugging/remote-debug-banner.ai',)
27 for spewer
in log_spewers
:
28 mapping
.pop(spewer
, None)
31 rpc
= memcache
.Client().set_multi_async(mapping
,
32 namespace
=self
._namespace
)
33 return Future(callback
=rpc
.get_result
)
34 except ValueError as e
:
35 logging
.error('Caught error when memcache-ing keys %s: %s' %
36 (mapping
.keys(), traceback
.format_exc()))
37 return Future(value
=None)
39 def GetMulti(self
, keys
):
40 rpc
= memcache
.Client().get_multi_async(keys
, namespace
=self
._namespace
)
41 return Future(callback
=rpc
.get_result
)
43 def DelMulti(self
, keys
):
44 memcache
.delete_multi(keys
, namespace
=self
._namespace
)