| Index: chrome/common/extensions/docs/server2/caching_file_system.py
|
| diff --git a/chrome/common/extensions/docs/server2/memcache_file_system.py b/chrome/common/extensions/docs/server2/caching_file_system.py
|
| similarity index 75%
|
| rename from chrome/common/extensions/docs/server2/memcache_file_system.py
|
| rename to chrome/common/extensions/docs/server2/caching_file_system.py
|
| index ae281dc58f65c85c06dd6f377cdaa468379ffc7e..592c23ade5149eee966b65ddebe9006205c63ef2 100644
|
| --- a/chrome/common/extensions/docs/server2/memcache_file_system.py
|
| +++ b/chrome/common/extensions/docs/server2/caching_file_system.py
|
| @@ -4,20 +4,18 @@
|
|
|
| from file_system import FileSystem, StatInfo, FileNotFoundError
|
| from future import Future
|
| -import object_store
|
| +from object_store_creator import ObjectStoreCreator
|
|
|
| class _AsyncUncachedFuture(object):
|
| def __init__(self,
|
| uncached,
|
| current_result,
|
| file_system,
|
| - object_store,
|
| - namespace):
|
| + object_store):
|
| self._uncached = uncached
|
| self._current_result = current_result
|
| self._file_system = file_system
|
| self._object_store = object_store
|
| - self._namespace = namespace
|
|
|
| def Get(self):
|
| mapping = {}
|
| @@ -26,22 +24,28 @@ class _AsyncUncachedFuture(object):
|
| version = self._file_system.Stat(item).version
|
| mapping[item] = (new_items[item], version)
|
| self._current_result[item] = new_items[item]
|
| - self._object_store.SetMulti(mapping, self._namespace, time=0)
|
| + self._object_store.SetMulti(mapping, time=0)
|
| return self._current_result
|
|
|
| -class MemcacheFileSystem(FileSystem):
|
| - """FileSystem implementation which memcaches the results of Read.
|
| +class CachingFileSystem(FileSystem):
|
| + """FileSystem implementation which caches its results in an object store.
|
| """
|
| - def __init__(self, file_system, object_store):
|
| + def __init__(self, file_system):
|
| self._file_system = file_system
|
| - self._object_store = object_store
|
| + object_store_creator = ObjectStoreCreator(CachingFileSystem)
|
| + self._stat_object_store = object_store_creator.Create(
|
| + category='stat')
|
| + self._read_object_store = object_store_creator.Create(
|
| + category='read')
|
| + self._read_binary_object_store = object_store_creator.Create(
|
| + category='read-binary')
|
|
|
| def Stat(self, path, stats=None):
|
| """Stats the directory given, or if a file is given, stats the files parent
|
| directory to get info about the file.
|
| """
|
| # TODO(kalman): store the whole stat info, not just the version.
|
| - version = self._object_store.Get(path, object_store.FILE_SYSTEM_STAT).Get()
|
| + version = self._stat_object_store.Get(path).Get()
|
| if version is not None:
|
| return StatInfo(version)
|
|
|
| @@ -64,7 +68,7 @@ class MemcacheFileSystem(FileSystem):
|
| for child_path, child_version in dir_stat.child_versions.iteritems():
|
| child_path = dir_path + child_path
|
| mapping[child_path] = child_version
|
| - self._object_store.SetMulti(mapping, object_store.FILE_SYSTEM_STAT)
|
| + self._stat_object_store.SetMulti(mapping)
|
| return StatInfo(version)
|
|
|
| def Read(self, paths, binary=False):
|
| @@ -73,13 +77,11 @@ class MemcacheFileSystem(FileSystem):
|
| """
|
| result = {}
|
| uncached = []
|
| - namespace = object_store.FILE_SYSTEM_READ
|
| - if binary:
|
| - namespace = '%s.binary' % namespace
|
| - results = self._object_store.GetMulti(paths, namespace, time=0).Get()
|
| + read_object_store = (self._read_binary_object_store if binary else
|
| + self._read_object_store)
|
| + results = read_object_store.GetMulti(paths).Get()
|
| result_values = [x[1] for x in sorted(results.iteritems())]
|
| - stats = self._object_store.GetMulti(paths,
|
| - object_store.FILE_SYSTEM_STAT).Get()
|
| + stats = self._stat_object_store.GetMulti(paths).Get()
|
| stat_values = [x[1] for x in sorted(stats.iteritems())]
|
| for path, cached_result, stat in zip(sorted(paths),
|
| result_values,
|
| @@ -102,5 +104,4 @@ class MemcacheFileSystem(FileSystem):
|
| self._file_system.Read(uncached, binary=binary),
|
| result,
|
| self,
|
| - self._object_store,
|
| - namespace))
|
| + read_object_store))
|
|
|