Show More
@@ -265,7 +265,6 b' class BaseRedisBackend(redis_backend.Red' | |||
|
265 | 265 | def get_mutex(self, key): |
|
266 | 266 | if self.distributed_lock: |
|
267 | 267 | lock_key = redis_backend.u('_lock_{0}').format(key) |
|
268 | log.debug('Trying to acquire Redis lock for key %s', lock_key) | |
|
269 | 268 | return get_mutex_lock(self.client, lock_key, self._lock_timeout, |
|
270 | 269 | auto_renewal=self._lock_auto_renewal) |
|
271 | 270 | else: |
@@ -298,12 +297,22 b' def get_mutex_lock(client, lock_key, loc' | |||
|
298 | 297 | strict=True, |
|
299 | 298 | ) |
|
300 | 299 | |
|
300 | def __repr__(self): | |
|
301 | return "{}:{}".format(self.__class__.__name__, lock_key) | |
|
302 | ||
|
303 | def __str__(self): | |
|
304 | return "{}:{}".format(self.__class__.__name__, lock_key) | |
|
305 | ||
|
301 | 306 | def __init__(self): |
|
302 | 307 | self.lock = self.get_lock() |
|
308 | self.lock_key = lock_key | |
|
303 | 309 | |
|
304 | 310 | def acquire(self, wait=True): |
|
311 | log.debug('Trying to acquire Redis lock for key %s', self.lock_key) | |
|
305 | 312 | try: |
|
306 |
|
|
|
313 | acquired = self.lock.acquire(wait) | |
|
314 | log.debug('Got lock for key %s, %s', self.lock_key, acquired) | |
|
315 | return acquired | |
|
307 | 316 | except redis_lock.AlreadyAcquired: |
|
308 | 317 | return False |
|
309 | 318 | except redis_lock.AlreadyStarted: |
@@ -18,6 +18,8 b'' | |||
|
18 | 18 | import os |
|
19 | 19 | import logging |
|
20 | 20 | import functools |
|
21 | import time | |
|
22 | ||
|
21 | 23 | from decorator import decorate |
|
22 | 24 | |
|
23 | 25 | from dogpile.cache import CacheRegion |
@@ -52,7 +54,11 b' class RhodeCodeCacheRegion(CacheRegion):' | |||
|
52 | 54 | |
|
53 | 55 | if not condition: |
|
54 | 56 | log.debug('Calling un-cached func:%s', user_func.func_name) |
|
55 | return user_func(*arg, **kw) | |
|
57 | start = time.time() | |
|
58 | result = user_func(*arg, **kw) | |
|
59 | total = time.time() - start | |
|
60 | log.debug('un-cached func:%s took %.4fs', user_func.func_name, total) | |
|
61 | return result | |
|
56 | 62 | |
|
57 | 63 | key = key_generator(*arg, **kw) |
|
58 | 64 | |
@@ -98,7 +104,6 b' class RhodeCodeCacheRegion(CacheRegion):' | |||
|
98 | 104 | user_func.original = user_func |
|
99 | 105 | |
|
100 | 106 | # Use `decorate` to preserve the signature of :param:`user_func`. |
|
101 | ||
|
102 | 107 | return decorate(user_func, functools.partial( |
|
103 | 108 | get_or_create_for_user_func, key_generator)) |
|
104 | 109 |
General Comments 0
You need to be logged in to leave comments.
Login now