##// 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 22 import beaker
23 23 import logging
24 import threading
24 25
25 26 from beaker.cache import _cache_decorate, cache_regions, region_invalidate
26 27
@@ -170,7 +171,7 b' class InvalidationContext(object):'
170 171 safe_str(self.repo_name), safe_str(self.cache_type))
171 172
172 173 def __init__(self, compute_func, repo_name, cache_type,
173 raise_exception=False):
174 raise_exception=False, thread_scoped=False):
174 175 self.compute_func = compute_func
175 176 self.repo_name = repo_name
176 177 self.cache_type = cache_type
@@ -178,6 +179,13 b' class InvalidationContext(object):'
178 179 repo_name, cache_type)
179 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 189 def get_cache_obj(self):
182 190 cache_key = CacheKey.get_cache_key(
183 191 self.repo_name, self.cache_type)
General Comments 0
You need to be logged in to leave comments. Login now