Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 # found in the LICENSE file. | |
| 4 | |
| 5 from lazy_value import LazyValue | |
| 6 | |
| 7 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.
| |
| 8 def __init__(self, file_system, memcache): | |
| 9 self._file_system = file_system | |
| 10 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.
| |
| 11 | |
| 12 def Stat(self, path): | |
| 13 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
| |
| 14 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.
| |
| 15 if stat_info is None: | |
| 16 stat_info = self._file_system.Stat(directory).version | |
| 17 self._memcache.set(directory, stat_info, time=60, namespace='directories') | |
| 18 return stat_info | |
| 19 | |
| 20 def Read(self, paths): | |
| 21 result = {} | |
| 22 uncached = [] | |
| 23 for path in paths: | |
| 24 cached_result = self._memcache.get(path) | |
| 25 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.
| |
| 26 uncached.append(path) | |
| 27 continue | |
| 28 data, version = cached_result | |
| 29 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.
| |
| 30 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.
| |
| 31 uncached.append(path) | |
| 32 continue | |
| 33 result[path] = LazyValue(value=data) | |
| 34 new_items = self._file_system.Read(uncached).Get() | |
| 35 for item in new_items: | |
| 36 version = self.Stat(item) | |
| 37 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.
| |
| 38 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.
| |
| 39 result.update(new_items) | |
| 40 return result | |
| OLD | NEW |