Chromium Code Reviews| Index: appengine/isolate/model.py |
| diff --git a/appengine/isolate/model.py b/appengine/isolate/model.py |
| index 123d6ba436dfb578408bffbfcd977ca2c30b4632..b92786864266c76fc70e14437d1d2224a530bccb 100644 |
| --- a/appengine/isolate/model.py |
| +++ b/appengine/isolate/model.py |
| @@ -135,6 +135,30 @@ def entry_key_from_id(key_id): |
| parent=datastore_utils.shard_key(hash_key, N, 'ContentShard')) |
| +def get_content(namespace, hash_key): |
| + """Returns the content from either memcache or datastore. |
|
M-A Ruel
2016/04/14 19:22:36
Returns the content from either memcache or datast
kjlubick
2016/04/14 19:59:07
Done.
|
| + |
| + This does NOT return data from GCS, it is up to the client to do that. |
| + |
| + The first argument in the tuple is the content, the second is either |
|
M-A Ruel
2016/04/14 19:22:36
Returns:
tuple(content, ContentEntry)
At most
kjlubick
2016/04/14 19:59:08
Done.
|
| + None, if loaded from memcache, or the entity, if loaded from datastore. |
| + |
| + Raises LookupError if the content cannot be found. |
| + Raises ValueError if the hash_key is invalid. |
| + """ |
| + memcache_entry = memcache.get(hash_key, namespace='table_%s' % namespace) |
| + if memcache_entry is not None: |
| + return (memcache_entry, None) |
| + else: |
| + # Raises ValueError |
| + key = get_entry_key(namespace, hash_key) |
| + entity = key.get() |
| + if entity is None: |
| + raise LookupError("namespace %s, key %s does not refer to anything" % |
| + (namespace, hash_key)) |
| + return (entity.content, entity) |
| + |
| + |
| def expiration_jitter(now, expiration): |
| """Returns expiration/next_tag pair to set in a ContentEntry.""" |
| jittered = random.uniform(1, 1.2) * expiration |