Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(229)

Side by Side Diff: appengine/findit/common/cache_decorator.py

Issue 2400283003: [Findit] Add skeleton code for delta test script. (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 """This module provides a decorator to cache the results of a function. 5 """This module provides a decorator to cache the results of a function.
6 6
7 Examples: 7 Examples:
8 1. Decorate a function: 8 1. Decorate a function:
9 @cache_decorator.Cached() 9 @cache_decorator.Cached()
10 def Test(a): 10 def Test(a):
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 all_data[key] = compressed_data 130 all_data[key] = compressed_data
131 131
132 keys_not_set = memcache.set_multi(all_data, time=expire_time) 132 keys_not_set = memcache.set_multi(all_data, time=expire_time)
133 return len(keys_not_set) == 0 133 return len(keys_not_set) == 0
134 134
135 135
136 def _DefaultKeyGenerator(func, args, kwargs): 136 def _DefaultKeyGenerator(func, args, kwargs):
137 """Generates a key from the function and arguments passed to it. 137 """Generates a key from the function and arguments passed to it.
138 138
139 Args: 139 Args:
140 func (function): An arbitrary function. 140 func (function): An abitrary function.
wrengr 2016/10/11 22:57:43 was correct before: "arbitrary"
Sharu Jiang 2016/10/12 01:18:20 Done.
lijeffrey 2016/10/20 15:52:14 nit: the previous spelling was correct
141 args (list): Positional arguments passed to ``func``. 141 args (list): Positional arguments passed to ``func``.
142 kwargs (dict): Keyword arguments passed to ``func``. 142 kwargs (dict): Keyword arguments passed to ``func``.
143 143
144 Returns: 144 Returns:
145 A string to represent a call to the given function with the given arguments. 145 A string to represent a call to the given function with the given arguments.
146 """ 146 """
147 params = inspect.getcallargs(func, *args, **kwargs) 147 params = inspect.getcallargs(func, *args, **kwargs)
148 for var_name in params: 148 for var_name in params:
149 if not hasattr(params[var_name], 'identifier'): 149 if not hasattr(params[var_name], 'identifier'):
150 continue 150 continue
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 except Exception: # pragma: no cover. 219 except Exception: # pragma: no cover.
220 logging.exception( 220 logging.exception(
221 'Failed to cache data for function %s.%s, args=%s, kwargs=%s', 221 'Failed to cache data for function %s.%s, args=%s, kwargs=%s',
222 func.__module__, func.__name__, repr(args), repr(kwargs)) 222 func.__module__, func.__name__, repr(args), repr(kwargs))
223 223
224 return result 224 return result
225 225
226 return Wrapped 226 return Wrapped
227 227
228 return Decorator 228 return Decorator
OLDNEW
« no previous file with comments | « no previous file | appengine/findit/crash/findit_for_chromecrash.py » ('j') | appengine/findit/crash/findit_for_chromecrash.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698