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

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

Issue 10704252: Extensions Docs Server: Internal file system (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixed up 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/fetcher_cache.py
diff --git a/chrome/common/extensions/docs/server2/fetcher_cache.py b/chrome/common/extensions/docs/server2/fetcher_cache.py
deleted file mode 100644
index 68cfdddb63a28f57eb49eb48983505590d6d8e99..0000000000000000000000000000000000000000
--- a/chrome/common/extensions/docs/server2/fetcher_cache.py
+++ /dev/null
@@ -1,55 +0,0 @@
-# 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.
-
-import os
-import time
-
-class FetcherCache(object):
- """A cache for fetcher objects.
- """
- class Builder(object):
- """A class to build a fetcher cache.
- """
- def __init__(self, fetcher, timeout_seconds):
- self._fetcher = fetcher
- self._timeout_seconds = timeout_seconds
-
- def build(self, populate_function):
- return FetcherCache(self._fetcher,
- self._timeout_seconds,
- populate_function)
-
- class _CacheEntry(object):
- def __init__(self, cache_data, expiry):
- self._cache_data = cache_data
- self._expiry = expiry
-
- def HasExpired(self):
- return time.time() > self._expiry
-
- def __init__(self, fetcher, timeout_seconds, populate_function):
- self._fetcher = fetcher
- self._timeout_seconds = timeout_seconds
- self._populate_function = populate_function
- self._cache = {}
-
- def _Fetch(self, fetch_func, key, optional_params=None):
- if key in self._cache:
- if self._cache[key].HasExpired():
- self._cache.pop(key)
- else:
- return self._cache[key]._cache_data
- if optional_params != None:
- cache_data = fetch_func(key, optional_params).content
- else:
- cache_data = fetch_func(key).content
- self._cache[key] = self._CacheEntry(self._populate_function(cache_data),
- time.time() + self._timeout_seconds)
- return self._cache[key]._cache_data
-
- def getFromFileListing(self, path, recursive=False):
- return self._Fetch(self._fetcher.ListDirectory, path, recursive)
-
- def getFromFile(self, key):
- return self._Fetch(self._fetcher.FetchResource, key)
« no previous file with comments | « chrome/common/extensions/docs/server2/fake_url_fetcher.py ('k') | chrome/common/extensions/docs/server2/file_system.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698