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

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

Issue 2456603003: [Predator] Add local cache for get command output. (Closed)
Patch Set: Rebase. Created 4 years, 1 month 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
« no previous file with comments | « no previous file | appengine/findit/util_scripts/local_cache.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 # 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
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
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
OLDNEW
« no previous file with comments | « no previous file | appengine/findit/util_scripts/local_cache.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698