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

Side by Side Diff: chrome/common/extensions/docs/server2/compiled_file_system.py

Issue 14218004: Devserver: only populate data during cron jobs, meaning all data from instances (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: PTAL Created 7 years, 8 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
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 class _CacheEntry(object): 5 class _CacheEntry(object):
6 def __init__(self, cache_data, version): 6 def __init__(self, cache_data, version):
7 self._cache_data = cache_data 7 self._cache_data = cache_data
8 self.version = version 8 self.version = version
9 9
10 class CompiledFileSystem(object): 10 class CompiledFileSystem(object):
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 files.append(filename) 82 files.append(filename)
83 return files 83 return files
84 84
85 def GetFromFile(self, path, binary=False): 85 def GetFromFile(self, path, binary=False):
86 """Calls |populate_function| on the contents of the file at |path|. If 86 """Calls |populate_function| on the contents of the file at |path|. If
87 |binary| is True then the file will be read as binary - but this will only 87 |binary| is True then the file will be read as binary - but this will only
88 apply for the first time the file is fetched; if already cached, |binary| 88 apply for the first time the file is fetched; if already cached, |binary|
89 will be ignored. 89 will be ignored.
90 """ 90 """
91 version = self._file_system.Stat(path).version 91 version = self._file_system.Stat(path).version
92 cache_entry = self._file_object_store.Get(path, time=0).Get() 92 cache_entry = self._file_object_store.Get(path).Get()
93 if (cache_entry is not None) and (version == cache_entry.version): 93 if (cache_entry is not None) and (version == cache_entry.version):
94 return cache_entry._cache_data 94 return cache_entry._cache_data
95 cache_data = self._populate_function( 95 cache_data = self._populate_function(
96 path, 96 path,
97 self._file_system.ReadSingle(path, binary=binary)) 97 self._file_system.ReadSingle(path, binary=binary))
98 self._file_object_store.Set(path, _CacheEntry(cache_data, version), time=0) 98 self._file_object_store.Set(path, _CacheEntry(cache_data, version))
99 return cache_data 99 return cache_data
100 100
101 def GetFromFileListing(self, path): 101 def GetFromFileListing(self, path):
102 """Calls |populate_function| on the listing of the files at |path|. 102 """Calls |populate_function| on the listing of the files at |path|.
103 Assumes that the path given is to a directory. 103 Assumes that the path given is to a directory.
104 """ 104 """
105 if not path.endswith('/'): 105 if not path.endswith('/'):
106 path += '/' 106 path += '/'
107 version = self._file_system.Stat(path).version 107 version = self._file_system.Stat(path).version
108 cache_entry = self._list_object_store.Get(path, time=0).Get() 108 cache_entry = self._list_object_store.Get(path).Get()
109 if (cache_entry is not None) and (version == cache_entry.version): 109 if (cache_entry is not None) and (version == cache_entry.version):
110 return cache_entry._cache_data 110 return cache_entry._cache_data
111 cache_data = self._populate_function(path, self._RecursiveList(path)) 111 cache_data = self._populate_function(path, self._RecursiveList(path))
112 self._list_object_store.Set(path, _CacheEntry(cache_data, version), time=0) 112 self._list_object_store.Set(path, _CacheEntry(cache_data, version))
113 return cache_data 113 return cache_data
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698