| OLD | NEW |
| 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 Loading... |
| 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 |
| OLD | NEW |