Show More
@@ -265,7 +265,6 b' class BaseRedisBackend(redis_backend.Red' | |||||
265 | def get_mutex(self, key): |
|
265 | def get_mutex(self, key): | |
266 | if self.distributed_lock: |
|
266 | if self.distributed_lock: | |
267 | lock_key = redis_backend.u('_lock_{0}').format(key) |
|
267 | lock_key = redis_backend.u('_lock_{0}').format(key) | |
268 | log.debug('Trying to acquire Redis lock for key %s', lock_key) |
|
|||
269 | return get_mutex_lock(self.client, lock_key, self._lock_timeout, |
|
268 | return get_mutex_lock(self.client, lock_key, self._lock_timeout, | |
270 | auto_renewal=self._lock_auto_renewal) |
|
269 | auto_renewal=self._lock_auto_renewal) | |
271 | else: |
|
270 | else: | |
@@ -298,12 +297,22 b' def get_mutex_lock(client, lock_key, loc' | |||||
298 | strict=True, |
|
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 | def __init__(self): |
|
306 | def __init__(self): | |
302 | self.lock = self.get_lock() |
|
307 | self.lock = self.get_lock() | |
|
308 | self.lock_key = lock_key | |||
303 |
|
309 | |||
304 | def acquire(self, wait=True): |
|
310 | def acquire(self, wait=True): | |
|
311 | log.debug('Trying to acquire Redis lock for key %s', self.lock_key) | |||
305 | try: |
|
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 | except redis_lock.AlreadyAcquired: |
|
316 | except redis_lock.AlreadyAcquired: | |
308 | return False |
|
317 | return False | |
309 | except redis_lock.AlreadyStarted: |
|
318 | except redis_lock.AlreadyStarted: |
@@ -18,6 +18,8 b'' | |||||
18 | import os |
|
18 | import os | |
19 | import logging |
|
19 | import logging | |
20 | import functools |
|
20 | import functools | |
|
21 | import time | |||
|
22 | ||||
21 | from decorator import decorate |
|
23 | from decorator import decorate | |
22 |
|
24 | |||
23 | from dogpile.cache import CacheRegion |
|
25 | from dogpile.cache import CacheRegion | |
@@ -52,7 +54,11 b' class RhodeCodeCacheRegion(CacheRegion):' | |||||
52 |
|
54 | |||
53 | if not condition: |
|
55 | if not condition: | |
54 | log.debug('Calling un-cached func:%s', user_func.func_name) |
|
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 | key = key_generator(*arg, **kw) |
|
63 | key = key_generator(*arg, **kw) | |
58 |
|
64 | |||
@@ -98,7 +104,6 b' class RhodeCodeCacheRegion(CacheRegion):' | |||||
98 | user_func.original = user_func |
|
104 | user_func.original = user_func | |
99 |
|
105 | |||
100 | # Use `decorate` to preserve the signature of :param:`user_func`. |
|
106 | # Use `decorate` to preserve the signature of :param:`user_func`. | |
101 |
|
||||
102 | return decorate(user_func, functools.partial( |
|
107 | return decorate(user_func, functools.partial( | |
103 | get_or_create_for_user_func, key_generator)) |
|
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