##// END OF EJS Templates
caches: use process aware settings cache with proper invalidation.
marcink -
r2937:23a83d11 default
parent child Browse files
Show More
@@ -3144,6 +3144,7 b' class CacheKey(Base, BaseModel):'
3144 3144 CACHE_TYPE_README = 'README'
3145 3145 # namespaces used to register process/thread aware caches
3146 3146 REPO_INVALIDATION_NAMESPACE = 'repo_cache:{repo_id}'
3147 SETTINGS_INVALIDATION_NAMESPACE = 'system_settings'
3147 3148
3148 3149 cache_id = Column("cache_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
3149 3150 cache_key = Column("cache_key", String(255), nullable=True, unique=None, default=None)
@@ -21,7 +21,6 b''
21 21 import os
22 22 import hashlib
23 23 import logging
24 import time
25 24 from collections import namedtuple
26 25 from functools import wraps
27 26 import bleach
@@ -32,7 +31,7 b' from rhodecode.lib.utils2 import ('
32 31 from rhodecode.lib.vcs.backends import base
33 32 from rhodecode.model import BaseModel
34 33 from rhodecode.model.db import (
35 RepoRhodeCodeUi, RepoRhodeCodeSetting, RhodeCodeUi, RhodeCodeSetting)
34 RepoRhodeCodeUi, RepoRhodeCodeSetting, RhodeCodeUi, RhodeCodeSetting, CacheKey)
36 35 from rhodecode.model.meta import Session
37 36
38 37
@@ -207,14 +206,12 b' class SettingsModel(BaseModel):'
207 206 return res
208 207
209 208 def invalidate_settings_cache(self):
210 # NOTE:(marcink) we flush the whole sql_cache_short region, because it
211 # reads different settings etc. It's little too much but those caches are
212 # anyway very short lived and it's a safest way.
213 region = rc_cache.get_or_create_region('sql_cache_short')
214 region.invalidate()
209 invalidation_namespace = CacheKey.SETTINGS_INVALIDATION_NAMESPACE
210 CacheKey.set_invalidate(invalidation_namespace)
215 211
216 212 def get_all_settings(self, cache=False):
217 213 region = rc_cache.get_or_create_region('sql_cache_short')
214 invalidation_namespace = CacheKey.SETTINGS_INVALIDATION_NAMESPACE
218 215
219 216 @region.conditional_cache_on_arguments(condition=cache)
220 217 def _get_all_settings(name, key):
@@ -230,10 +227,23 b' class SettingsModel(BaseModel):'
230 227
231 228 repo = self._get_repo(self.repo) if self.repo else None
232 229 key = "settings_repo.{}".format(repo.repo_id) if repo else "settings_app"
233 start = time.time()
230
231 inv_context_manager = rc_cache.InvalidationContext(
232 uid='cache_settings', invalidation_namespace=invalidation_namespace)
233 with inv_context_manager as invalidation_context:
234 # check for stored invalidation signal, and maybe purge the cache
235 # before computing it again
236 if invalidation_context.should_invalidate():
237 # NOTE:(marcink) we flush the whole sql_cache_short region, because it
238 # reads different settings etc. It's little too much but those caches
239 # are anyway very short lived and it's a safest way.
240 region = rc_cache.get_or_create_region('sql_cache_short')
241 region.invalidate()
242
234 243 result = _get_all_settings('rhodecode_settings', key)
235 total = time.time() - start
236 log.debug('Fetching app settings for key: %s took: %.3fs', key, total)
244 log.debug(
245 'Fetching app settings for key: %s took: %.3fs', key,
246 inv_context_manager.compute_time)
237 247
238 248 return result
239 249
General Comments 0
You need to be logged in to leave comments. Login now