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

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

Issue 14267024: Devserver: have a separate ObjectStore namespace (both memcache and datastore) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove _CheckVersions 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 from file_system import FileSystem, StatInfo, FileNotFoundError 5 from file_system import FileSystem, StatInfo, FileNotFoundError
6 from future import Future 6 from future import Future
7 7
8 class _AsyncUncachedFuture(object): 8 class _AsyncUncachedFuture(object):
9 def __init__(self, 9 def __init__(self,
10 uncached, 10 uncached,
(...skipping 15 matching lines...) Expand all
26 self._object_store.SetMulti(mapping) 26 self._object_store.SetMulti(mapping)
27 return self._current_result 27 return self._current_result
28 28
29 class CachingFileSystem(FileSystem): 29 class CachingFileSystem(FileSystem):
30 """FileSystem implementation which caches its results in an object store. 30 """FileSystem implementation which caches its results in an object store.
31 """ 31 """
32 def __init__(self, file_system, object_store_creator_factory): 32 def __init__(self, file_system, object_store_creator_factory):
33 self._file_system = file_system 33 self._file_system = file_system
34 def create_object_store(category): 34 def create_object_store(category):
35 return (object_store_creator_factory.Create(CachingFileSystem) 35 return (object_store_creator_factory.Create(CachingFileSystem)
36 .Create(category='%s/%s' % (file_system.GetName(), category), 36 .Create(category='%s/%s' % (file_system.GetName(), category)))
37 version=file_system.GetVersion()))
38 self._stat_object_store = create_object_store('stat') 37 self._stat_object_store = create_object_store('stat')
39 self._read_object_store = create_object_store('read') 38 self._read_object_store = create_object_store('read')
40 self._read_binary_object_store = create_object_store('read-binary') 39 self._read_binary_object_store = create_object_store('read-binary')
41 40
42 def Stat(self, path, stats=None): 41 def Stat(self, path, stats=None):
43 """Stats the directory given, or if a file is given, stats the file's parent 42 """Stats the directory given, or if a file is given, stats the file's parent
44 directory to get info about the file. 43 directory to get info about the file.
45 """ 44 """
46 # TODO(kalman): store the whole stat info, not just the version. 45 # TODO(kalman): store the whole stat info, not just the version.
47 version = self._stat_object_store.Get(path).Get() 46 version = self._stat_object_store.Get(path).Get()
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 result[path] = data 95 result[path] = data
97 96
98 if not uncached: 97 if not uncached:
99 return Future(value=result) 98 return Future(value=result)
100 99
101 return Future(delegate=_AsyncUncachedFuture( 100 return Future(delegate=_AsyncUncachedFuture(
102 self._file_system.Read(uncached, binary=binary), 101 self._file_system.Read(uncached, binary=binary),
103 result, 102 result,
104 self, 103 self,
105 read_object_store)) 104 read_object_store))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698