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.
6 # This will attempt to import the actual App Engine modules, and if it fails,
7 # they will be replaced with fake modules. This is useful during testing.
9 import google
.appengine
.api
.memcache
as memcache
12 def __init__(self
, result
=None):
22 class InMemoryMemcache(object):
23 """An in-memory memcache implementation.
29 def set_multi_async(self
, mapping
, namespace
='', time
=0):
30 return _RPC(result
=dict(
31 (k
, memcache
.set(k
, v
, namespace
=namespace
, time
=time
))
32 for k
, v
in mapping
.iteritems()))
34 def get_multi_async(self
, keys
, namespace
='', time
=0):
35 return _RPC(result
=dict(
36 (k
, memcache
.get(k
, namespace
=namespace
, time
=time
)) for k
in keys
))
38 def set(self
, key
, value
, namespace
='', time
=0):
39 self
._GetNamespace
(namespace
)[key
] = value
41 def get(self
, key
, namespace
='', time
=0):
42 return self
._GetNamespace
(namespace
).get(key
)
44 def delete(self
, key
, namespace
=''):
45 self
._GetNamespace
(namespace
).pop(key
, None)
47 def delete_multi(self
, keys
, namespace
=''):
49 self
.delete(k
, namespace
=namespace
)
51 def _GetNamespace(self
, namespace
):
52 if namespace
not in self
._namespaces
:
53 self
._namespaces
[namespace
] = {}
54 return self
._namespaces
[namespace
]
60 memcache
= InMemoryMemcache()