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

Unified Diff: chrome/common/extensions/docs/server2/caching_file_system.py

Issue 660383002: Docserver: Persist stat cache for versioned file systems (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: chrome/common/extensions/docs/server2/caching_file_system.py
diff --git a/chrome/common/extensions/docs/server2/caching_file_system.py b/chrome/common/extensions/docs/server2/caching_file_system.py
index b0573716f1fbc2fa56cc68e163bd5d627a9f2856..bacb9ed8ab111ad72af2d87f85399a426d3d01e5 100644
--- a/chrome/common/extensions/docs/server2/caching_file_system.py
+++ b/chrome/common/extensions/docs/server2/caching_file_system.py
@@ -14,16 +14,19 @@ from third_party.json_schema_compiler.memoize import memoize
class CachingFileSystem(FileSystem):
'''FileSystem which implements a caching layer on top of |file_system|. It's
smart, using Stat() to decided whether to skip Read()ing from |file_system|,
- and only Stat()ing directories never files.
+ and only Stat()ing directories never files. If |fail_on_miss| is True, then
+ stat cache misses are treated like FileNotFound, rather than falling back onto
+ the underlying filesystem.
'''
- def __init__(self, file_system, object_store_creator):
+ def __init__(self, file_system, object_store_creator, fail_on_miss=False):
self._file_system = file_system
+ self._fail_on_miss = fail_on_miss
def create_object_store(category, **optargs):
return object_store_creator.Create(
CachingFileSystem,
category='%s/%s' % (file_system.GetIdentity(), category),
**optargs)
- self._stat_cache = create_object_store('stat')
+ self._stat_cache = create_object_store('stat', start_empty=False)
# The read caches can start populated (start_empty=False) because file
# updates are picked up by the stat, so it doesn't need the force-refresh
# which starting empty is designed for. Without this optimisation, cron
@@ -56,10 +59,16 @@ class CachingFileSystem(FileSystem):
(path, dir_path, dir_stat.child_versions))
return StatInfo(file_version)
+ def raise_not_found(path):
+ raise FileNotFoundError('Got 404 when stat\'ing %s' % path)
not at google - send to devlin 2014/10/20 21:06:57 It might complicate things for callers - but can w
Ken Rockot(use gerrit already) 2014/10/22 03:19:54 Will do, but it will take longer to sort that out.
+
dir_stat = self._stat_cache.Get(dir_path).Get()
if dir_stat is not None:
return Future(callback=lambda: make_stat_info(dir_stat))
+ if self._fail_on_miss:
+ return Future(callback=lambda: raise_not_found(dir_path))
+
def next(dir_stat):
assert dir_stat is not None # should have raised a FileNotFoundError
# We only ever need to cache the dir stat.
@@ -169,12 +178,6 @@ class CachingFileSystem(FileSystem):
return dirs, files
return self._file_system.Walk(root, depth=depth, file_lister=file_lister)
- def GetCommitID(self):
- return self._file_system.GetCommitID()
-
- def GetPreviousCommitID(self):
- return self._file_system.GetPreviousCommitID()
-
def GetIdentity(self):
return self._file_system.GetIdentity()

Powered by Google App Engine
This is Rietveld 408576698