| OLD | NEW |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 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 import cStringIO | 5 import cStringIO |
| 6 import pickle | 6 import pickle |
| 7 import zlib | 7 import zlib |
| 8 | 8 |
| 9 from google.appengine.api import memcache | 9 from google.appengine.api import memcache |
| 10 | 10 |
| 11 from lib.cache import Cache | 11 from libs.cache import Cache |
| 12 | 12 |
| 13 | 13 |
| 14 class PickledMemCache(Cache): | 14 class PickledMemCache(Cache): |
| 15 """A memcache-backed implementation of the interface Cache. | 15 """A memcache-backed implementation of the interface Cache. |
| 16 | 16 |
| 17 The data to be cached should be pickleable. | 17 The data to be cached should be pickleable. |
| 18 Limitation: size of the pickled data and key should be <= 1MB. | 18 Limitation: size of the pickled data and key should be <= 1MB. |
| 19 """ | 19 """ |
| 20 def Get(self, key): | 20 def Get(self, key): |
| 21 return memcache.get(key) | 21 return memcache.get(key) |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 all_data[sub_key] = compressed_data[index : index + self.CHUNK_SIZE] | 66 all_data[sub_key] = compressed_data[index : index + self.CHUNK_SIZE] |
| 67 num += 1 | 67 num += 1 |
| 68 | 68 |
| 69 all_data[key] = _CachedItemMetaData(num) | 69 all_data[key] = _CachedItemMetaData(num) |
| 70 else: | 70 else: |
| 71 all_data[key] = compressed_data | 71 all_data[key] = compressed_data |
| 72 | 72 |
| 73 keys_not_set = memcache.set_multi(all_data, time=expire_time) | 73 keys_not_set = memcache.set_multi(all_data, time=expire_time) |
| 74 return len(keys_not_set) == 0 | 74 return len(keys_not_set) == 0 |
| 75 | 75 |
| OLD | NEW |