| 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. |
| 6 |
| 5 """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. |
| 6 | 8 |
| 7 Examples: | 9 Examples: |
| 8 1. Decorate a function: | 10 1. Decorate a function: |
| 9 @cache_decorator.Cached() | 11 @cache_decorator.Cached() |
| 10 def Test(a): | 12 def Test(a): |
| 11 return a + a | 13 return a + a |
| 12 | 14 |
| 13 Test('a') | 15 Test('a') |
| 14 Test('a') # Returns the cached 'aa'. | 16 Test('a') # Returns the cached 'aa'. |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 except Exception: # pragma: no cover. | 221 except Exception: # pragma: no cover. |
| 220 logging.exception( | 222 logging.exception( |
| 221 'Failed to cache data for function %s.%s, args=%s, kwargs=%s', | 223 'Failed to cache data for function %s.%s, args=%s, kwargs=%s', |
| 222 func.__module__, func.__name__, repr(args), repr(kwargs)) | 224 func.__module__, func.__name__, repr(args), repr(kwargs)) |
| 223 | 225 |
| 224 return result | 226 return result |
| 225 | 227 |
| 226 return Wrapped | 228 return Wrapped |
| 227 | 229 |
| 228 return Decorator | 230 return Decorator |
| OLD | NEW |