| 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
|
|
|