Show More
@@ -23,14 +23,8 b' loggers = {' | |||
|
23 | 23 | ] |
|
24 | 24 | } |
|
25 | 25 | |
|
26 | PY3 = sys.version_info[0] == 3 | |
|
27 | ||
|
28 | if PY3: | |
|
29 | text_type = str | |
|
30 | binary_type = bytes | |
|
31 | else: | |
|
32 | text_type = unicode # noqa | |
|
33 | binary_type = str | |
|
26 | text_type = str | |
|
27 | binary_type = bytes | |
|
34 | 28 | |
|
35 | 29 | |
|
36 | 30 | # Check if the id match. If not, return an error code. |
@@ -1,14 +1,7 b'' | |||
|
1 | 1 | |
|
2 | 2 | |
|
3 | 3 | import functools |
|
4 | ||
|
5 | # Use timer that's not susceptible to time of day adjustments. | |
|
6 | try: | |
|
7 | # perf_counter is only present on Py3.3+ | |
|
8 | from time import perf_counter as time_now | |
|
9 | except ImportError: | |
|
10 | # fall back to using time | |
|
11 | from time import time as time_now | |
|
4 | from time import perf_counter as time_now | |
|
12 | 5 | |
|
13 | 6 | |
|
14 | 7 | def safe_wraps(wrapper, *args, **kwargs): |
@@ -19,6 +19,7 b' import os' | |||
|
19 | 19 | import time |
|
20 | 20 | import logging |
|
21 | 21 | import functools |
|
22 | import decorator | |
|
22 | 23 | |
|
23 | 24 | from dogpile.cache import CacheRegion |
|
24 | 25 | |
@@ -47,61 +48,6 b' class RhodeCodeCacheRegion(CacheRegion):' | |||
|
47 | 48 | if function_key_generator is None: |
|
48 | 49 | function_key_generator = self.function_key_generator |
|
49 | 50 | |
|
50 | # workaround for py2 and cython problems, this block should be removed | |
|
51 | # once we've migrated to py3 | |
|
52 | if 'cython' == 'cython': | |
|
53 | def decorator(fn): | |
|
54 | if to_str is str: | |
|
55 | # backwards compatible | |
|
56 | key_generator = function_key_generator(namespace, fn) | |
|
57 | else: | |
|
58 | key_generator = function_key_generator(namespace, fn, to_str=to_str) | |
|
59 | ||
|
60 | @functools.wraps(fn) | |
|
61 | def decorate(*arg, **kw): | |
|
62 | key = key_generator(*arg, **kw) | |
|
63 | ||
|
64 | @functools.wraps(fn) | |
|
65 | def creator(): | |
|
66 | return fn(*arg, **kw) | |
|
67 | ||
|
68 | if not condition: | |
|
69 | return creator() | |
|
70 | ||
|
71 | timeout = expiration_time() if expiration_time_is_callable \ | |
|
72 | else expiration_time | |
|
73 | ||
|
74 | return self.get_or_create(key, creator, timeout, should_cache_fn) | |
|
75 | ||
|
76 | def invalidate(*arg, **kw): | |
|
77 | key = key_generator(*arg, **kw) | |
|
78 | self.delete(key) | |
|
79 | ||
|
80 | def set_(value, *arg, **kw): | |
|
81 | key = key_generator(*arg, **kw) | |
|
82 | self.set(key, value) | |
|
83 | ||
|
84 | def get(*arg, **kw): | |
|
85 | key = key_generator(*arg, **kw) | |
|
86 | return self.get(key) | |
|
87 | ||
|
88 | def refresh(*arg, **kw): | |
|
89 | key = key_generator(*arg, **kw) | |
|
90 | value = fn(*arg, **kw) | |
|
91 | self.set(key, value) | |
|
92 | return value | |
|
93 | ||
|
94 | decorate.set = set_ | |
|
95 | decorate.invalidate = invalidate | |
|
96 | decorate.refresh = refresh | |
|
97 | decorate.get = get | |
|
98 | decorate.original = fn | |
|
99 | decorate.key_generator = key_generator | |
|
100 | decorate.__wrapped__ = fn | |
|
101 | ||
|
102 | return decorate | |
|
103 | return decorator | |
|
104 | ||
|
105 | 51 | def get_or_create_for_user_func(key_generator, user_func, *arg, **kw): |
|
106 | 52 | |
|
107 | 53 | if not condition: |
General Comments 0
You need to be logged in to leave comments.
Login now