| OLD | NEW |
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 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 # TODO(http://crbug.com/660466): We should try to break dependencies. | 5 # TODO(http://crbug.com/660466): We should try to break dependencies. |
| 6 | 6 |
| 7 """This module provides a decorator to cache the results of a function. | 7 """This module provides a decorator to cache the results of a function. |
| 8 | 8 |
| 9 Examples: | 9 Examples: |
| 10 1. Decorate a function: | 10 1. Decorate a function: |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 import functools | 40 import functools |
| 41 import hashlib | 41 import hashlib |
| 42 import inspect | 42 import inspect |
| 43 import logging | 43 import logging |
| 44 import pickle | 44 import pickle |
| 45 import zlib | 45 import zlib |
| 46 | 46 |
| 47 from google.appengine.api import memcache | 47 from google.appengine.api import memcache |
| 48 | 48 |
| 49 | 49 |
| 50 # TODO(katesonia): Change this to a better name, e.g. Cache. |
| 50 class Cacher(object): | 51 class Cacher(object): |
| 51 """An interface to cache and retrieve data. | 52 """An interface to cache and retrieve data. |
| 52 | 53 |
| 53 Subclasses should implement the Get/Set functions. | 54 Subclasses should implement the Get/Set functions. |
| 54 TODO: Add a Delete function (default to no-op) if needed later. | 55 TODO: Add a Delete function (default to no-op) if needed later. |
| 55 """ | 56 """ |
| 56 def Get(self, key): | 57 def Get(self, key): |
| 57 """Returns the cached data for the given key if available. | 58 """Returns the cached data for the given key if available. |
| 58 | 59 |
| 59 Args: | 60 Args: |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 except Exception: # pragma: no cover. | 222 except Exception: # pragma: no cover. |
| 222 logging.exception( | 223 logging.exception( |
| 223 'Failed to cache data for function %s.%s, args=%s, kwargs=%s', | 224 'Failed to cache data for function %s.%s, args=%s, kwargs=%s', |
| 224 func.__module__, func.__name__, repr(args), repr(kwargs)) | 225 func.__module__, func.__name__, repr(args), repr(kwargs)) |
| 225 | 226 |
| 226 return result | 227 return result |
| 227 | 228 |
| 228 return Wrapped | 229 return Wrapped |
| 229 | 230 |
| 230 return Decorator | 231 return Decorator |
| OLD | NEW |