##// END OF EJS Templates
caches: make sure the global cache namespace prefixes are used....
super-admin -
r5106:4e5efedc default
parent child Browse files
Show More
@@ -624,10 +624,10 b' def get_repo_fts_tree(request, apiuser, '
624 624 cache_seconds = rhodecode.ConfigGet().get_int('rc_cache.cache_repo.expiration_time')
625 625 cache_on = cache_seconds > 0
626 626
627 cache_namespace_uid = f'repo.{repo_id}'
627 cache_namespace_uid = f'repo.{rc_cache.FILE_TREE_CACHE_VER}.{repo_id}'
628 628 rc_cache.get_or_create_region('cache_repo', cache_namespace_uid)
629 629
630 def compute_fts_tree(cache_ver, repo_id, commit_id, root_path):
630 def compute_fts_tree(repo_id, commit_id, root_path):
631 631 return ScmModel().get_fts_data(repo_id, commit_id, root_path)
632 632
633 633 try:
@@ -648,7 +648,7 b' def get_repo_fts_tree(request, apiuser, '
648 648 'with caching: %s[TTL: %ss]' % (
649 649 repo_id, commit_id, cache_on, cache_seconds or 0))
650 650
651 tree_files = compute_fts_tree(rc_cache.FILE_TREE_CACHE_VER, repo_id, commit_id, root_path)
651 tree_files = compute_fts_tree(repo_id, commit_id, root_path)
652 652
653 653 return tree_files
654 654
@@ -26,10 +26,10 b' log = logging.getLogger(__name__)'
26 26 # names of namespaces used for different permission related cached
27 27 # during flush operation we need to take care of all those
28 28 cache_namespaces = [
29 'cache_user_auth.{}',
30 'cache_user_repo_acl_ids.{}',
31 'cache_user_user_group_acl_ids.{}',
32 'cache_user_repo_group_acl_ids.{}'
29 f'cache_user_auth.{rc_cache.PERMISSIONS_CACHE_VER}.{{}}',
30 f'cache_user_repo_acl_ids.{rc_cache.PERMISSIONS_CACHE_VER}.{{}}',
31 f'cache_user_user_group_acl_ids.{rc_cache.PERMISSIONS_CACHE_VER}.{{}}',
32 f'cache_user_repo_group_acl_ids.{rc_cache.PERMISSIONS_CACHE_VER}.{{}}'
33 33 ]
34 34
35 35
@@ -1294,7 +1294,7 b' class UsersView(UserAppView):'
1294 1294 c.active = 'caches'
1295 1295 c.perm_user = c.user.AuthUser(ip_addr=self.request.remote_addr)
1296 1296
1297 cache_namespace_uid = f'cache_user_auth.{self.db_user.user_id}'
1297 cache_namespace_uid = f'cache_user_auth.{rc_cache.PERMISSIONS_CACHE_VER}.{self.db_user.user_id}'
1298 1298 c.region = rc_cache.get_or_create_region('cache_perms', cache_namespace_uid)
1299 1299 c.backend = c.region.backend
1300 1300 c.user_keys = sorted(c.region.backend.list_keys(prefix=cache_namespace_uid))
@@ -1312,7 +1312,7 b' class UsersView(UserAppView):'
1312 1312 c.active = 'caches'
1313 1313 c.perm_user = c.user.AuthUser(ip_addr=self.request.remote_addr)
1314 1314
1315 cache_namespace_uid = f'cache_user_auth.{self.db_user.user_id}'
1315 cache_namespace_uid = f'cache_user_auth.{rc_cache.PERMISSIONS_CACHE_VER}.{self.db_user.user_id}'
1316 1316 del_keys = rc_cache.clear_cache_namespace('cache_perms', cache_namespace_uid)
1317 1317
1318 1318 h.flash(_("Deleted {} cache keys").format(del_keys), category='success')
@@ -310,13 +310,13 b' class RepoFilesView(RepoAppView):'
310 310 'with caching: %s[TTL: %ss]' % (
311 311 repo_id, commit_id, f_path, cache_on, cache_seconds or 0))
312 312
313 cache_namespace_uid = f'repo.{repo_id}'
313 cache_namespace_uid = f'repo.{rc_cache.FILE_TREE_CACHE_VER}.{repo_id}'
314 314 region = rc_cache.get_or_create_region('cache_repo', cache_namespace_uid)
315 315
316 316 @region.conditional_cache_on_arguments(namespace=cache_namespace_uid, condition=cache_on)
317 def compute_file_tree(ver, _name_hash, _repo_id, _commit_id, _f_path, _full_load, _at_rev):
317 def compute_file_tree(_name_hash, _repo_id, _commit_id, _f_path, _full_load, _at_rev):
318 318 log.debug('Generating cached file tree at ver:%s for repo_id: %s, %s, %s',
319 ver, _repo_id, _commit_id, _f_path)
319 _repo_id, _commit_id, _f_path)
320 320
321 321 c.full_load = _full_load
322 322 return render(
@@ -324,8 +324,7 b' class RepoFilesView(RepoAppView):'
324 324 self._get_template_context(c), self.request, _at_rev)
325 325
326 326 return compute_file_tree(
327 rc_cache.FILE_TREE_CACHE_VER, self.db_repo.repo_name_hash,
328 self.db_repo.repo_id, commit_id, f_path, full_load, at_rev)
327 self.db_repo.repo_name_hash, self.db_repo.repo_id, commit_id, f_path, full_load, at_rev)
329 328
330 329 def create_pure_path(self, *parts):
331 330 # Split paths and sanitize them, removing any ../ etc
@@ -750,7 +750,7 b' def authenticate(username, password, env'
750 750 user_id = user.user_id if user else 'no-user'
751 751 # don't cache for empty users
752 752 plugin_cache_active = plugin_cache_active and user_id
753 cache_namespace_uid = f'cache_user_auth.{user_id}'
753 cache_namespace_uid = f'cache_user_auth.{rc_cache.PERMISSIONS_CACHE_VER}.{user_id}'
754 754 region = rc_cache.get_or_create_region('cache_perms', cache_namespace_uid)
755 755
756 756 @region.conditional_cache_on_arguments(namespace=cache_namespace_uid,
@@ -125,7 +125,7 b' class AuthenticationPluginRegistry(objec'
125 125
126 126 @classmethod
127 127 def get_cache_region(cls):
128 cache_namespace_uid = 'auth_plugins'
128 cache_namespace_uid = 'auth_plugins.v1'
129 129 region = rc_cache.get_or_create_region('cache_general', cache_namespace_uid)
130 130 return region, cache_namespace_uid
131 131
@@ -1255,7 +1255,7 b' class AuthUser(object):'
1255 1255 'Computing PERMISSION tree for user %s scope `%s` '
1256 1256 'with caching: %s[TTL: %ss]', user, scope, cache_on, cache_seconds or 0)
1257 1257
1258 cache_namespace_uid = f'cache_user_auth.{user_id}'
1258 cache_namespace_uid = f'cache_user_auth.{rc_cache.PERMISSIONS_CACHE_VER}.{user_id}'
1259 1259 region = rc_cache.get_or_create_region('cache_perms', cache_namespace_uid)
1260 1260
1261 1261 @region.conditional_cache_on_arguments(namespace=cache_namespace_uid,
@@ -1358,7 +1358,7 b' class AuthUser(object):'
1358 1358
1359 1359 log.debug('Computing REPO ACL IDS user %s', self)
1360 1360
1361 cache_namespace_uid = 'cache_user_repo_acl_ids.{}'.format(self.user_id)
1361 cache_namespace_uid = f'cache_user_repo_acl_ids.{rc_cache.PERMISSIONS_CACHE_VER}.{self.user_id}'
1362 1362 region = rc_cache.get_or_create_region('cache_perms', cache_namespace_uid)
1363 1363
1364 1364 @region.conditional_cache_on_arguments(namespace=cache_namespace_uid, condition=cache)
@@ -1409,7 +1409,7 b' class AuthUser(object):'
1409 1409
1410 1410 log.debug('Computing REPO GROUP ACL IDS user %s', self)
1411 1411
1412 cache_namespace_uid = 'cache_user_repo_group_acl_ids.{}'.format(self.user_id)
1412 cache_namespace_uid = f'cache_user_repo_group_acl_ids.{rc_cache.PERMISSIONS_CACHE_VER}.{self.user_id}'
1413 1413 region = rc_cache.get_or_create_region('cache_perms', cache_namespace_uid)
1414 1414
1415 1415 @region.conditional_cache_on_arguments(namespace=cache_namespace_uid, condition=cache)
@@ -1458,7 +1458,7 b' class AuthUser(object):'
1458 1458
1459 1459 log.debug('Computing USER GROUP ACL IDS user %s', self)
1460 1460
1461 cache_namespace_uid = 'cache_user_user_group_acl_ids.{}'.format(self.user_id)
1461 cache_namespace_uid = f'cache_user_user_group_acl_ids.{rc_cache.PERMISSIONS_CACHE_VER}.{self.user_id}'
1462 1462 region = rc_cache.get_or_create_region('cache_perms', cache_namespace_uid)
1463 1463
1464 1464 @region.conditional_cache_on_arguments(namespace=cache_namespace_uid, condition=cache)
@@ -314,7 +314,7 b' class SimpleVCS(object):'
314 314 plugin_id, plugin_cache_active, cache_ttl)
315 315
316 316 user_id = user.user_id
317 cache_namespace_uid = 'cache_user_auth.{}'.format(user_id)
317 cache_namespace_uid = f'cache_user_auth.{rc_cache.PERMISSIONS_CACHE_VER}.{user_id}'
318 318 region = rc_cache.get_or_create_region('cache_perms', cache_namespace_uid)
319 319
320 320 @region.conditional_cache_on_arguments(namespace=cache_namespace_uid,
@@ -56,9 +56,9 b' register_backend('
56 56 log = logging.getLogger(__name__)
57 57
58 58
59 FILE_TREE_CACHE_VER = 'v4'
60 LICENSE_CACHE_VER = 'v2'
61
59 FILE_TREE_CACHE_VER = 'v5'
60 LICENSE_CACHE_VER = 'v3'
61 PERMISSIONS_CACHE_VER = 'v2'
62 62
63 63 CLEAR_DELETE = 'delete'
64 64 CLEAR_INVALIDATE = 'invalidate'
@@ -111,7 +111,7 b' def configure_dogpile_cache(settings):'
111 111 if log.isEnabledFor(logging.DEBUG):
112 112 region_args = dict(backend=new_region.actual_backend,
113 113 region_invalidator=new_region.region_invalidator.__class__)
114 log.debug('dogpile: registering a new region `%s` %s', namespace_name, region_args)
114 log.debug('dogpile: registering a new region key=`%s` args=%s', namespace_name, region_args)
115 115
116 116 region_meta.dogpile_cache_regions[namespace_name] = new_region
117 117
@@ -28,7 +28,7 b' from dogpile.cache import CacheRegion'
28 28 import rhodecode
29 29 from rhodecode.lib.hash_utils import sha1
30 30 from rhodecode.lib.str_utils import safe_bytes
31 from rhodecode.lib.type_utils import str2bool
31 from rhodecode.lib.type_utils import str2bool # noqa :required by imports from .utils
32 32
33 33 from . import region_meta, cache_key_meta
34 34
@@ -185,6 +185,7 b' def get_or_create_region(region_name, re'
185 185
186 186 region_uid_name = f'{region_name}:{region_namespace}'
187 187
188 # Special case for ONLY the FileNamespaceBackend backend. We register one-file-per-region
188 189 if isinstance(region_obj.actual_backend, FileNamespaceBackend):
189 190 if not region_namespace:
190 191 raise ValueError(f'{FileNamespaceBackend} used requires to specify region_namespace param')
@@ -200,7 +201,7 b' def get_or_create_region(region_name, re'
200 201 namespace_cache_dir = cache_dir
201 202
202 203 # we default the namespace_cache_dir to our default cache dir.
203 # however if this backend is configured with filename= param, we prioritize that
204 # however, if this backend is configured with filename= param, we prioritize that
204 205 # so all caches within that particular region, even those namespaced end up in the same path
205 206 if region_obj.actual_backend.filename:
206 207 namespace_cache_dir = os.path.dirname(region_obj.actual_backend.filename)
@@ -280,7 +281,7 b' class InvalidationContext(object):'
280 281 from rhodecode.lib import rc_cache
281 282
282 283 cache_namespace_uid = CacheKey.SOME_NAMESPACE.format(1)
283 region = rc_cache.get_or_create_region('cache_perms', cache_namespace_uid)
284 region = rc_cache.get_or_create_region('some_region', cache_namespace_uid)
284 285
285 286 @region.conditional_cache_on_arguments(namespace=cache_namespace_uid, condition=True)
286 287 def heavy_compute(cache_name, param1, param2):
@@ -3675,7 +3675,7 b' class CacheKey(Base, BaseModel):'
3675 3675 CACHE_TYPE_FEED = 'FEED'
3676 3676
3677 3677 # namespaces used to register process/thread aware caches
3678 REPO_INVALIDATION_NAMESPACE = 'repo_cache:{repo_id}'
3678 REPO_INVALIDATION_NAMESPACE = 'repo_cache.v1:{repo_id}'
3679 3679
3680 3680 cache_id = Column("cache_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
3681 3681 cache_key = Column("cache_key", String(255), nullable=True, unique=None, default=None)
@@ -210,7 +210,7 b' class SettingsModel(BaseModel):'
210 210
211 211 def get_cache_region(self):
212 212 repo = self._get_repo(self.repo) if self.repo else None
213 cache_key = f"repo.{repo.repo_id}" if repo else "repo.ALL"
213 cache_key = f"repo.v1.{repo.repo_id}" if repo else "repo.v1.ALL"
214 214 cache_namespace_uid = f'cache_settings.{cache_key}'
215 215 region = rc_cache.get_or_create_region('cache_general', cache_namespace_uid)
216 216 return region, cache_namespace_uid
@@ -37,8 +37,7 b' class TestCaches(object):'
37 37 ])
38 38 def test_cache_decorator_init(self, region_name):
39 39 namespace = region_name
40 cache_region = rc_cache.get_or_create_region(
41 region_name, region_namespace=namespace)
40 cache_region = rc_cache.get_or_create_region(region_name, region_namespace=namespace)
42 41 assert cache_region
43 42
44 43 @pytest.mark.parametrize('example_input', [
General Comments 0
You need to be logged in to leave comments. Login now