From 3f31c5bd8b2a4cc613d5d3da9bd902117dcf3028 Mon Sep 17 00:00:00 2001 From: Marcin Kuzminski Date: Fri, 10 Aug 2018 10:27:35 +0200 Subject: [PATCH] caches: use context based cache for repository. - due to gevent sharing connections problem we have to make the cache key per each green thread. --- rhodecode/model/db.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/rhodecode/model/db.py b/rhodecode/model/db.py index fdeac1e4..47b4fd95 100644 --- a/rhodecode/model/db.py +++ b/rhodecode/model/db.py @@ -2336,16 +2336,17 @@ class Repository(Base, BaseModel): region = rc_cache.get_or_create_region('cache_repo_longterm', cache_namespace_uid) @region.conditional_cache_on_arguments(namespace=cache_namespace_uid) - def get_instance_cached(repo_id): + def get_instance_cached(repo_id, context_id): return self._get_instance() # we must use thread scoped cache here, - # because each thread of gevent needs it's own connection and cache + # because each thread of gevent needs it's own not shared connection and cache + # we also alter `args` so the cache key is individual for every green thread. inv_context_manager = rc_cache.InvalidationContext( uid=cache_namespace_uid, invalidation_namespace=invalidation_namespace, thread_scoped=True) with inv_context_manager as invalidation_context: - args = (self.repo_id,) + args = (self.repo_id, inv_context_manager.cache_key) # re-compute and store cache if we get invalidate signal if invalidation_context.should_invalidate(): instance = get_instance_cached.refresh(*args)