##// END OF EJS Templates
caches: use individual namespaces per user to prevent beaker caching problems....
marcink -
r2591:36829a17 stable
parent child Browse files
Show More
@@ -578,14 +578,20 b' def get_authn_registry(registry=None):'
578 578 return authn_registry
579 579
580 580
581 def get_auth_cache_manager(custom_ttl=None):
581 def get_auth_cache_manager(custom_ttl=None, suffix=None):
582 cache_name = 'rhodecode.authentication'
583 if suffix:
584 cache_name = 'rhodecode.authentication.{}'.format(suffix)
582 585 return caches.get_cache_manager(
583 'auth_plugins', 'rhodecode.authentication', custom_ttl)
586 'auth_plugins', cache_name, custom_ttl)
584 587
585 588
586 def get_perms_cache_manager(custom_ttl=None):
589 def get_perms_cache_manager(custom_ttl=None, suffix=None):
590 cache_name = 'rhodecode.permissions'
591 if suffix:
592 cache_name = 'rhodecode.permissions.{}'.format(suffix)
587 593 return caches.get_cache_manager(
588 'auth_plugins', 'rhodecode.permissions', custom_ttl)
594 'auth_plugins', cache_name, custom_ttl)
589 595
590 596
591 597 def authenticate(username, password, environ=None, auth_type=None,
@@ -646,7 +652,8 b' def authenticate(username, password, env'
646 652 plugin_cache_active, cache_ttl = plugin.get_ttl_cache(plugin_settings)
647 653
648 654 # get instance of cache manager configured for a namespace
649 cache_manager = get_auth_cache_manager(custom_ttl=cache_ttl)
655 cache_manager = get_auth_cache_manager(
656 custom_ttl=cache_ttl, suffix=user.user_id)
650 657
651 658 log.debug('AUTH_CACHE_TTL for plugin `%s` active: %s (TTL: %s)',
652 659 plugin.get_id(), plugin_cache_active, cache_ttl)
@@ -32,6 +32,7 b' from rhodecode.authentication.base impor'
32 32 from rhodecode.lib import helpers as h
33 33 from rhodecode.lib.auth import (
34 34 LoginRequired, HasPermissionAllDecorator, CSRFRequired)
35 from rhodecode.lib.caches import clear_cache_manager
35 36 from rhodecode.model.forms import AuthSettingsForm
36 37 from rhodecode.model.meta import Session
37 38 from rhodecode.model.settings import SettingsModel
@@ -101,6 +102,16 b' class AuthnPluginViewBase(BaseAppView):'
101 102 self.plugin.create_or_update_setting(name, value)
102 103 Session().commit()
103 104
105 # cleanup cache managers in case of change for plugin
106 # TODO(marcink): because we can register multiple namespaces
107 # we should at some point figure out how to retrieve ALL namespace
108 # cache managers and clear them...
109 cache_manager = get_auth_cache_manager()
110 clear_cache_manager(cache_manager)
111
112 cache_manager = get_perms_cache_manager()
113 clear_cache_manager(cache_manager)
114
104 115 # Display success message and redirect.
105 116 h.flash(_('Auth settings updated successfully.'), category='success')
106 117 redirect_to = self.request.resource_path(
@@ -161,12 +172,6 b' class AuthSettingsView(BaseAppView):'
161 172 Session().add(setting)
162 173 Session().commit()
163 174
164 cache_manager = get_auth_cache_manager()
165 cache_manager.clear()
166
167 cache_manager = get_perms_cache_manager()
168 cache_manager.clear()
169
170 175 h.flash(_('Auth settings updated successfully.'), category='success')
171 176 except formencode.Invalid as errors:
172 177 e = errors.error_dict or {}
@@ -288,7 +288,8 b' class SimpleVCS(object):'
288 288 """
289 289
290 290 # get instance of cache manager configured for a namespace
291 cache_manager = get_perms_cache_manager(custom_ttl=cache_ttl)
291 cache_manager = get_perms_cache_manager(
292 custom_ttl=cache_ttl, suffix=user.user_id)
292 293 log.debug('AUTH_CACHE_TTL for permissions `%s` active: %s (TTL: %s)',
293 294 plugin_id, plugin_cache_active, cache_ttl)
294 295
General Comments 0
You need to be logged in to leave comments. Login now