Chromium Code Reviews| 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 |
| index 68cfdddb63a28f57eb49eb48983505590d6d8e99..487844a22fda882c0f68c66f961a0ac39df66209 100644 |
| --- a/chrome/common/extensions/docs/server2/fetcher_cache.py |
| +++ b/chrome/common/extensions/docs/server2/fetcher_cache.py |
| @@ -34,22 +34,39 @@ class FetcherCache(object): |
| self._populate_function = populate_function |
| self._cache = {} |
| - def _Fetch(self, fetch_func, key, optional_params=None): |
| + def _FetchFile(self, filename): |
| + return self._fetcher.Read([filename])[filename] |
| + |
| + def _RecursiveList(self, files): |
| + all_files = files[:] |
| + dirs = {} |
| + for filename in files: |
| + if filename.endswith('/'): |
| + all_files.remove(filename) |
| + dirs.update(self._fetcher.Read([filename])) |
| + for dir_, files in dirs.iteritems(): |
| + all_files.extend(self._RecursiveList([dir_ + f for f in files.Get()])) |
| + return all_files |
| + |
| + def getFromFile(self, key): |
|
not at google - send to devlin
2012/07/18 10:39:15
document
and key -> path
cduvall
2012/07/18 21:26:10
Done.
|
| 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 |
| + cache_data = self._FetchFile(key).Get() |
| 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) |
| + def getFromFileListing(self, key): |
|
not at google - send to devlin
2012/07/18 10:39:15
document
also key -> path
btw this method should
cduvall
2012/07/18 21:26:10
Done.
|
| + if key in self._cache: |
| + if self._cache[key].HasExpired(): |
| + self._cache.pop(key) |
| + else: |
| + return self._cache[key]._cache_data |
| + cache_data = self._RecursiveList( |
| + [key + f for f in self._FetchFile(key).Get()]) |
| + self._cache[key] = self._CacheEntry(self._populate_function(cache_data), |
| + time.time() + self._timeout_seconds) |
| + return self._cache[key]._cache_data |