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

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

Issue 2538373003: [Culprit-Finder] Merge lib/ to libs/. (Closed)
Patch Set: . Created 4 years 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 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
11 from lib.cache import Cache 11 from libs.cache import Cache
12 12
13 CACHE_DIR = os.path.join(os.path.expanduser('~'), '.predator', 'cache') 13 CACHE_DIR = os.path.join(os.path.expanduser('~'), '.predator', 'cache')
14 14
15 15
16 class LocalCache(Cache): 16 class LocalCache(Cache):
17 """Cacher that uses local files to cache data.""" 17 """Cacher that uses local files to cache data."""
18 lock = threading.Lock() 18 lock = threading.Lock()
19 19
20 def __init__(self, cache_dir=CACHE_DIR): 20 def __init__(self, cache_dir=CACHE_DIR):
21 self.cache_dir = cache_dir 21 self.cache_dir = cache_dir
(...skipping 14 matching lines...) Expand all
36 except Exception as error: # pragma: no cover. 36 except Exception as error: # pragma: no cover.
37 raise Exception('Failed loading cache: %s' % error) 37 raise Exception('Failed loading cache: %s' % error)
38 38
39 def Set(self, key, data, expire_time=0): # pylint: disable=W 39 def Set(self, key, data, expire_time=0): # pylint: disable=W
40 with LocalCache.lock: 40 with LocalCache.lock:
41 try: 41 try:
42 with open(os.path.join(self.cache_dir, key), 'wb') as f: 42 with open(os.path.join(self.cache_dir, key), 'wb') as f:
43 f.write(zlib.compress(pickle.dumps(data))) 43 f.write(zlib.compress(pickle.dumps(data)))
44 except Exception as e: # pragma: no cover. 44 except Exception as e: # pragma: no cover.
45 raise Exception('Failed setting cache for key %s: %s' % (key, e)) 45 raise Exception('Failed setting cache for key %s: %s' % (key, e))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698