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

Side by Side 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, 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 from google.appengine.api import urlfetch
6 import logging
7
8 import appengine_memcache as memcache
9
10 class MemcacheUrlFetcher(object):
11 """A wrapper around the App Engine urlfetch module that memcaches results.
12 """
13 def __init__(self, memcache, base_path):
14 self._memcache = memcache
15 self._base_path = base_path
16
17 def Fetch(self, url):
18 """Fetches a file synchronously, and memcaches the result for 60 seconds.
19 """
20 content = self._memcache.Get(url, memcache.MEMCACHE_URL_FETCHER)
21 if content is not None:
22 return content
23 content = urlfetch.fetch(self._base_path + '/' + url).content
24 try:
25 self._memcache.Set(url, content, memcache.MEMCACHE_URL_FETCHER)
26 except Exception as e:
27 logging.info(e)
28 return content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698