##// END OF EJS Templates
caches: Add an argument to make the cache context thread scoped.
Martin Bornhold -
r613:af6adc7d default
parent child Browse files
Show More
@@ -21,6 +21,7 b''
21
21
22 import beaker
22 import beaker
23 import logging
23 import logging
24 import threading
24
25
25 from beaker.cache import _cache_decorate, cache_regions, region_invalidate
26 from beaker.cache import _cache_decorate, cache_regions, region_invalidate
26
27
@@ -170,7 +171,7 b' class InvalidationContext(object):'
170 safe_str(self.repo_name), safe_str(self.cache_type))
171 safe_str(self.repo_name), safe_str(self.cache_type))
171
172
172 def __init__(self, compute_func, repo_name, cache_type,
173 def __init__(self, compute_func, repo_name, cache_type,
173 raise_exception=False):
174 raise_exception=False, thread_scoped=False):
174 self.compute_func = compute_func
175 self.compute_func = compute_func
175 self.repo_name = repo_name
176 self.repo_name = repo_name
176 self.cache_type = cache_type
177 self.cache_type = cache_type
@@ -178,6 +179,13 b' class InvalidationContext(object):'
178 repo_name, cache_type)
179 repo_name, cache_type)
179 self.raise_exception = raise_exception
180 self.raise_exception = raise_exception
180
181
182 # Append the thread id to the cache key if this invalidation context
183 # should be scoped to the current thread.
184 if thread_scoped:
185 thread_id = threading.current_thread().ident
186 self.cache_key = '{cache_key}_{thread_id}'.format(
187 cache_key=self.cache_key, thread_id=thread_id)
188
181 def get_cache_obj(self):
189 def get_cache_obj(self):
182 cache_key = CacheKey.get_cache_key(
190 cache_key = CacheKey.get_cache_key(
183 self.repo_name, self.cache_type)
191 self.repo_name, self.cache_type)
General Comments 0
You need to be logged in to leave comments. Login now