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

Unified Diff: chrome/common/extensions/docs/server2/memcache_url_fetcher.py

Issue 10825067: Extensions Docs Server: Apps samples page (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: chrome/common/extensions/docs/server2/memcache_url_fetcher.py
diff --git a/chrome/common/extensions/docs/server2/memcache_url_fetcher.py b/chrome/common/extensions/docs/server2/memcache_url_fetcher.py
new file mode 100644
index 0000000000000000000000000000000000000000..9b732e9ecf7f3889c152ab1b0823ea242049161b
--- /dev/null
+++ b/chrome/common/extensions/docs/server2/memcache_url_fetcher.py
@@ -0,0 +1,28 @@
+# Copyright (c) 2012 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+from google.appengine.api import urlfetch
+import logging
+
+import appengine_memcache as memcache
+
+class MemcacheUrlFetcher(object):
+ """A wrapper around the App Engine urlfetch module that memcaches results.
+ """
+ def __init__(self, memcache, base_path):
+ self._memcache = memcache
+ self._base_path = base_path
+
+ def Fetch(self, url):
+ """Fetches a file synchronously, and memcaches the result for 60 seconds.
+ """
+ content = self._memcache.Get(url, memcache.MEMCACHE_URL_FETCHER)
+ if content is not None:
+ return content
+ content = urlfetch.fetch(self._base_path + '/' + url).content
+ try:
+ self._memcache.Set(url, content, memcache.MEMCACHE_URL_FETCHER)
+ except Exception as e:
+ logging.info(e)
+ return content

Powered by Google App Engine
This is Rietveld 408576698