caches: Add an argument to make the cache context thread scoped.
This commit is contained in:
parent
6fce04f6d1
commit
da72f73efb
1 changed files with 9 additions and 1 deletions
|
|
@ -21,6 +21,7 @@
|
|||
|
||||
import beaker
|
||||
import logging
|
||||
import threading
|
||||
|
||||
from beaker.cache import _cache_decorate, cache_regions, region_invalidate
|
||||
|
||||
|
|
@ -170,7 +171,7 @@ class InvalidationContext(object):
|
|||
safe_str(self.repo_name), safe_str(self.cache_type))
|
||||
|
||||
def __init__(self, compute_func, repo_name, cache_type,
|
||||
raise_exception=False):
|
||||
raise_exception=False, thread_scoped=False):
|
||||
self.compute_func = compute_func
|
||||
self.repo_name = repo_name
|
||||
self.cache_type = cache_type
|
||||
|
|
@ -178,6 +179,13 @@ class InvalidationContext(object):
|
|||
repo_name, cache_type)
|
||||
self.raise_exception = raise_exception
|
||||
|
||||
# Append the thread id to the cache key if this invalidation context
|
||||
# should be scoped to the current thread.
|
||||
if thread_scoped:
|
||||
thread_id = threading.current_thread().ident
|
||||
self.cache_key = '{cache_key}_{thread_id}'.format(
|
||||
cache_key=self.cache_key, thread_id=thread_id)
|
||||
|
||||
def get_cache_obj(self):
|
||||
cache_key = CacheKey.get_cache_key(
|
||||
self.repo_name, self.cache_type)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue