OLD | NEW |
---|---|
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 | 5 from file_system import FileSystem |
6 from future import Future | 6 from future import Future |
7 import appengine_memcache as memcache | 7 import appengine_memcache as memcache |
8 | 8 |
9 class MemcacheFileSystem(FileSystem): | 9 class MemcacheFileSystem(FileSystem): |
10 """FileSystem implementation which memcaches the results of Read. | 10 """FileSystem implementation which memcaches the results of Read. |
(...skipping 22 matching lines...) Expand all Loading... | |
33 """ | 33 """ |
34 result = {} | 34 result = {} |
35 uncached = [] | 35 uncached = [] |
36 for path in paths: | 36 for path in paths: |
37 cached_result = self._memcache.Get(path, | 37 cached_result = self._memcache.Get(path, |
38 memcache.MEMCACHE_FILE_SYSTEM_READ) | 38 memcache.MEMCACHE_FILE_SYSTEM_READ) |
39 if cached_result is None: | 39 if cached_result is None: |
40 uncached.append(path) | 40 uncached.append(path) |
41 continue | 41 continue |
42 data, version = cached_result | 42 data, version = cached_result |
43 if self.Stat(path).version > version: | 43 if self._file_system.CheckStat(self.Stat(path).version, version): |
not at google - send to devlin
2012/08/02 13:27:48
yeah, needs to be != (and besides, I don't think t
cduvall
2012/08/02 23:20:01
Done.
| |
44 self._memcache.Delete(path, memcache.MEMCACHE_FILE_SYSTEM_READ) | 44 self._memcache.Delete(path, memcache.MEMCACHE_FILE_SYSTEM_READ) |
45 uncached.append(path) | 45 uncached.append(path) |
46 continue | 46 continue |
47 result[path] = data | 47 result[path] = data |
48 new_items = self._file_system.Read(uncached, binary=binary).Get() | 48 new_items = self._file_system.Read(uncached, binary=binary).Get() |
49 for item in new_items: | 49 for item in new_items: |
50 version = self.Stat(item).version | 50 version = self.Stat(item).version |
51 value = new_items[item] | 51 value = new_items[item] |
52 self._memcache.Set(item, | 52 self._memcache.Set(item, |
53 (value, version), | 53 (value, version), |
54 memcache.MEMCACHE_FILE_SYSTEM_READ) | 54 memcache.MEMCACHE_FILE_SYSTEM_READ) |
55 result[item] = value | 55 result[item] = value |
56 return Future(value=result) | 56 return Future(value=result) |
OLD | NEW |