##// END OF EJS Templates
caches: remove settings cache to use invalidation context as it's slowing down much usage
super-admin -
r4833:54305e88 default
parent child Browse files
Show More
@@ -581,19 +581,24 b' def sanitize_settings_and_apply_defaults'
581 581 settings_maker.make_setting('exception_tracker.send_email', False, parser='bool')
582 582 settings_maker.make_setting('exception_tracker.email_prefix', '[RHODECODE ERROR]', default_when_empty=True)
583 583
584 # cache_general
585 settings_maker.make_setting('rc_cache.cache_general.backend', 'dogpile.cache.rc.file_namespace')
586 settings_maker.make_setting('rc_cache.cache_general.expiration_time', 60 * 60 * 12, parser='int')
587 settings_maker.make_setting('rc_cache.cache_general.arguments.filename', os.path.join(default_cache_dir, 'rhodecode_cache_general.db'))
588
584 589 # cache_perms
585 590 settings_maker.make_setting('rc_cache.cache_perms.backend', 'dogpile.cache.rc.file_namespace')
586 settings_maker.make_setting('rc_cache.cache_perms.expiration_time', 60, parser='int')
591 settings_maker.make_setting('rc_cache.cache_perms.expiration_time', 60 * 60, parser='int')
587 592 settings_maker.make_setting('rc_cache.cache_perms.arguments.filename', os.path.join(default_cache_dir, 'rhodecode_cache_perms.db'))
588 593
589 594 # cache_repo
590 595 settings_maker.make_setting('rc_cache.cache_repo.backend', 'dogpile.cache.rc.file_namespace')
591 settings_maker.make_setting('rc_cache.cache_repo.expiration_time', 60, parser='int')
596 settings_maker.make_setting('rc_cache.cache_repo.expiration_time', 60 * 60 * 24 * 30, parser='int')
592 597 settings_maker.make_setting('rc_cache.cache_repo.arguments.filename', os.path.join(default_cache_dir, 'rhodecode_cache_repo.db'))
593 598
594 599 # cache_license
595 600 settings_maker.make_setting('rc_cache.cache_license.backend', 'dogpile.cache.rc.file_namespace')
596 settings_maker.make_setting('rc_cache.cache_license.expiration_time', 5*60, parser='int')
601 settings_maker.make_setting('rc_cache.cache_license.expiration_time', 60 * 5, parser='int')
597 602 settings_maker.make_setting('rc_cache.cache_license.arguments.filename', os.path.join(default_cache_dir, 'rhodecode_cache_license.db'))
598 603
599 604 # cache_repo_longterm memory, 96H
@@ -31,6 +31,7 b' from rhodecode.lib import rc_cache'
31 31 from rhodecode.lib.utils2 import (
32 32 Optional, AttributeDict, safe_str, remove_prefix, str2bool)
33 33 from rhodecode.lib.vcs.backends import base
34 from rhodecode.lib.statsd_client import StatsdClient
34 35 from rhodecode.model import BaseModel
35 36 from rhodecode.model.db import (
36 37 RepoRhodeCodeUi, RepoRhodeCodeSetting, RhodeCodeUi, RhodeCodeSetting, CacheKey)
@@ -208,16 +209,28 b' class SettingsModel(BaseModel):'
208 209 Session().add(res)
209 210 return res
210 211
212 def get_cache_region(self):
213 repo = self._get_repo(self.repo) if self.repo else None
214 cache_key = "repo.{}".format(repo.repo_id) if repo else "general_settings"
215 cache_namespace_uid = 'cache_settings.{}'.format(cache_key)
216 region = rc_cache.get_or_create_region('cache_general', cache_namespace_uid)
217 return region, cache_key
218
211 219 def invalidate_settings_cache(self):
212 invalidation_namespace = CacheKey.SETTINGS_INVALIDATION_NAMESPACE
213 CacheKey.set_invalidate(invalidation_namespace)
220 from rhodecode.authentication.base import get_authn_registry
221
222 region, cache_key = self.get_cache_region()
223 log.debug('Invalidation cache region %s for cache_key: %s', region, cache_key)
224 region.invalidate()
225 registry = get_current_registry()
226 if registry:
227 authn_registry = get_authn_registry(registry)
228 if authn_registry:
229 authn_registry.invalidate_plugins_for_auth()
214 230
215 231 def get_all_settings(self, cache=False, from_request=True):
216 from rhodecode.authentication.base import get_authn_registry
217
218 232 # defines if we use GLOBAL, or PER_REPO
219 233 repo = self._get_repo(self.repo) if self.repo else None
220 key = "settings_repo.{}".format(repo.repo_id) if repo else "settings_app"
221 234
222 235 # initially try the requests context, this is the fastest
223 236 # we only fetch global config
@@ -229,8 +242,7 b' class SettingsModel(BaseModel):'
229 242 if rc_config:
230 243 return rc_config
231 244
232 region = rc_cache.get_or_create_region('sql_cache_short')
233 invalidation_namespace = CacheKey.SETTINGS_INVALIDATION_NAMESPACE
245 region, cache_key = self.get_cache_region()
234 246
235 247 @region.conditional_cache_on_arguments(condition=cache)
236 248 def _get_all_settings(name, key):
@@ -239,31 +251,17 b' class SettingsModel(BaseModel):'
239 251 raise Exception('Could not get application settings !')
240 252
241 253 settings = {
242 'rhodecode_' + result.app_settings_name: result.app_settings_value
243 for result in q
254 'rhodecode_' + res.app_settings_name: res.app_settings_value
255 for res in q
244 256 }
245 257 return settings
246 258
247 inv_context_manager = rc_cache.InvalidationContext(
248 uid='cache_settings', invalidation_namespace=invalidation_namespace)
249 with inv_context_manager as invalidation_context:
250 # check for stored invalidation signal, and maybe purge the cache
251 # before computing it again
252 if invalidation_context.should_invalidate():
253 # NOTE:(marcink) we flush the whole sql_cache_short region, because it
254 # reads different settings etc. It's little too much but those caches
255 # are anyway very short lived and it's a safest way.
256 region = rc_cache.get_or_create_region('sql_cache_short')
257 region.invalidate()
258 registry = get_current_registry()
259 if registry:
260 authn_registry = get_authn_registry(registry)
261 if authn_registry:
262 authn_registry.invalidate_plugins_for_auth()
259 statsd = StatsdClient.statsd
260 with statsd.timer('rhodecode_settings_timing.histogram', auto_send=True) as tmr:
261 result = _get_all_settings('rhodecode_settings', cache_key)
263 262
264 result = _get_all_settings('rhodecode_settings', key)
265 log.debug('Fetching app settings for key: %s took: %.4fs', key,
266 inv_context_manager.compute_time)
263 compute_time = tmr.ms / 1000.
264 log.debug('Fetching app settings for key: %s took: %.4fs', cache_key, compute_time)
267 265
268 266 return result
269 267
General Comments 0
You need to be logged in to leave comments. Login now