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

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

Issue 10825067: Extensions Docs Server: Apps samples page (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: blobstore Created 8 years, 4 months 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 | Annotate | Revision Log
OLDNEW
(Empty)
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.
4
5 import appengine_memcache as memcache
6 from appengine_memcache import AppEngineMemcache
7 from appengine_wrappers import blobstore
8 from appengine_wrappers import files
9
10 class AppEngineBlobstore(object):
11 """A wrapper around the blobstore API, which stores the blob keys in memcache
12 and in memory. The blob keys are stored in both places in case the blob key
13 gets flushed from memcache.
14 """
not at google - send to devlin 2012/08/07 01:35:38 methods could do with some documentation, e.g. wha
cduvall 2012/08/08 19:27:25 Done.
15 def __init__(self):
16 self._memcache = AppEngineMemcache('blobstore')
17 self._blob_keys = {}
not at google - send to devlin 2012/08/07 01:35:38 If the keys are only stored in volatile memory (me
cduvall 2012/08/08 19:27:25 Done.
18
19 def Set(self, blob, key, version):
not at google - send to devlin 2012/08/07 01:35:38 usually the key would be before the value in the p
cduvall 2012/08/08 19:27:25 Done.
20 key = key + '.' + str(version)
21 filename = files.blobstore.create()
22 with files.open(filename, 'a') as f:
23 f.write(blob)
24 files.finalize(filename)
25 blob_key = files.blobstore.get_blob_key(filename)
26 self._blob_keys[key] = blob_key
27 self._memcache.Set(key, blob_key, memcache.MEMCACHE_BLOBSTORE, time=0)
28
29 def Get(self, key, version):
30 key = key + '.' + str(version)
31 if key not in self._blob_keys:
32 blob_key = self._memcache.Get(key, memcache.MEMCACHE_BLOBSTORE)
33 if blob_key is None:
34 return None
35 self._blob_keys[key] = blob_key
36 else:
37 blob_key = self._blob_keys[key]
38 blob_reader = blobstore.BlobReader(blob_key)
39 return blob_reader.read()
40
41 def Delete(self, key, version):
42 key = key + '.' + str(version)
43 if key not in self._blob_keys:
44 blob_key = self._memcache.Get(key, memcache.MEMCACHE_BLOBSTORE)
45 if blob_key is None:
46 return
47 else:
48 blob_key = self._blob_keys[key]
49 self._blob_keys.pop(key)
50 blobstore.delete(blob_key)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698