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

Side by Side Diff: appengine/findit/util_scripts/local_cache.py

Issue 2432203003: [Predator] Run predator. (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 | « appengine/findit/util_scripts/iterator.py ('k') | appengine/findit/util_scripts/script_util.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 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 logging 5 import logging
6 import os 6 import os
7 import pickle 7 import pickle
8 import threading 8 import threading
9 import zlib 9 import zlib
10 10
(...skipping 15 matching lines...) Expand all
26 def Get(self, key): 26 def Get(self, key):
27 with LocalCacher.lock: 27 with LocalCacher.lock:
28 path = os.path.join(self.cache_dir, key) 28 path = os.path.join(self.cache_dir, key)
29 if not os.path.exists(path): 29 if not os.path.exists(path):
30 return None 30 return None
31 31
32 try: 32 try:
33 with open(path) as f: 33 with open(path) as f:
34 return pickle.loads(zlib.decompress(f.read())) 34 return pickle.loads(zlib.decompress(f.read()))
35 except Exception as error: # pragma: no cover. 35 except Exception as error: # pragma: no cover.
36 logging.exception('Failed loading cache: %s', error) 36 raise Exception('Failed loading cache: %s' % error)
37 return None
38 37
39 def Set(self, key, data, expire_time=0): # pylint: disable=W 38 def Set(self, key, data, expire_time=0): # pylint: disable=W
40 with LocalCacher.lock: 39 with LocalCacher.lock:
41 try: 40 try:
42 with open(os.path.join(self.cache_dir, key), 'wb') as f: 41 with open(os.path.join(self.cache_dir, key), 'wb') as f:
43 f.write(zlib.compress(pickle.dumps(data))) 42 f.write(zlib.compress(pickle.dumps(data)))
44 except Exception as e: # pragma: no cover. 43 except Exception as e: # pragma: no cover.
45 logging.exception('Failed setting cache for key %s: %s', key, e) 44 raise Exception('Failed setting cache for key %s: %s' % (key, e))
OLDNEW
« no previous file with comments | « appengine/findit/util_scripts/iterator.py ('k') | appengine/findit/util_scripts/script_util.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698