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

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

Issue 10704252: Extensions Docs Server: Internal file system (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Tests Created 8 years, 5 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/memcache_file_system.py
diff --git a/chrome/common/extensions/docs/server2/memcache_file_system.py b/chrome/common/extensions/docs/server2/memcache_file_system.py
new file mode 100644
index 0000000000000000000000000000000000000000..a6e17cefc18bf73f184b564700a4554aee91077a
--- /dev/null
+++ b/chrome/common/extensions/docs/server2/memcache_file_system.py
@@ -0,0 +1,40 @@
+# Copyright (c) 2012 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+from lazy_value import LazyValue
+
+class MemcacheFileSystem(object):
not at google - send to devlin 2012/07/18 10:39:15 documentation etc. Why does this not extend FileSy
cduvall 2012/07/18 21:26:10 Done.
+ def __init__(self, file_system, memcache):
+ self._file_system = file_system
+ self._memcache = memcache
not at google - send to devlin 2012/07/18 10:39:15 Class needs tests! And for that you'll probably ne
cduvall 2012/07/18 21:26:10 Done.
+
+ def Stat(self, path):
+ directory = path.rsplit('/', 1)[0]
not at google - send to devlin 2012/07/18 10:39:15 Stat should be at the path level, not the director
cduvall 2012/07/18 21:26:10 We can only stat directories, not files. See 3 com
not at google - send to devlin 2012/07/19 03:55:18 Ah I see. Bummer, this would be so neat (see comme
+ stat_info = self._memcache.get(directory, namespace='directories')
not at google - send to devlin 2012/07/18 10:39:15 we should be more disciplined with these namespace
cduvall 2012/07/18 21:26:10 Done.
+ if stat_info is None:
+ stat_info = self._file_system.Stat(directory).version
+ self._memcache.set(directory, stat_info, time=60, namespace='directories')
+ return stat_info
+
+ def Read(self, paths):
+ result = {}
+ uncached = []
+ for path in paths:
+ cached_result = self._memcache.get(path)
+ if cached_result is None:
not at google - send to devlin 2012/07/18 10:39:16 what's wrong with ==
cduvall 2012/07/18 21:26:10 See previous comment.
+ uncached.append(path)
+ continue
+ data, version = cached_result
+ if self.Stat(path) > version:
not at google - send to devlin 2012/07/18 10:39:16 So this means that if any file in a directory chan
cduvall 2012/07/18 21:26:10 The only problem with this: We can't stat files, j
not at google - send to devlin 2012/07/19 03:55:18 See comment above.
+ self._memcache.delete(path)
not at google - send to devlin 2012/07/18 10:39:16 also missing namespace
cduvall 2012/07/18 21:26:10 Done.
+ uncached.append(path)
+ continue
+ result[path] = LazyValue(value=data)
+ new_items = self._file_system.Read(uncached).Get()
+ for item in new_items:
+ version = self.Stat(item)
+ self._memcache.set(item, (new_items[item], version), namespace='data')
not at google - send to devlin 2012/07/18 10:39:16 set but never get? Oh, the get is missing its nam
cduvall 2012/07/18 21:26:10 Done.
+ new_items[item] = LazyValue(value=new_items[item])
not at google - send to devlin 2012/07/18 10:39:16 why not result[item] = LazyValue(value=new_items[i
cduvall 2012/07/18 21:26:10 Why not? Because I'm a dummy.
+ result.update(new_items)
+ return result

Powered by Google App Engine
This is Rietveld 408576698