Chromium Code Reviews| 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 |