##// END OF EJS Templates
caches: introduce invalidation as a safer ways to expire keys, deleting them are more problematic.
super-admin -
r4722:2e56987b default
parent child Browse files
Show More
@@ -41,13 +41,14 b' def trigger_user_permission_flush(event)'
41 41 automatic flush of permission caches, so the users affected receive new permissions
42 42 Right Away
43 43 """
44
44 invalidate = True
45 45 affected_user_ids = set(event.user_ids)
46 46 for user_id in affected_user_ids:
47 47 for cache_namespace_uid_tmpl in cache_namespaces:
48 48 cache_namespace_uid = cache_namespace_uid_tmpl.format(user_id)
49 del_keys = rc_cache.clear_cache_namespace('cache_perms', cache_namespace_uid)
50 log.debug('Deleted %s cache keys for user_id: %s and namespace %s',
49 del_keys = rc_cache.clear_cache_namespace(
50 'cache_perms', cache_namespace_uid, invalidate=invalidate)
51 log.debug('Invalidated %s cache keys for user_id: %s and namespace %s',
51 52 del_keys, user_id, cache_namespace_uid)
52 53
53 54
@@ -261,12 +261,15 b' def get_or_create_region(region_name, re'
261 261 return region_obj
262 262
263 263
264 def clear_cache_namespace(cache_region, cache_namespace_uid):
264 def clear_cache_namespace(cache_region, cache_namespace_uid, invalidate=False):
265 265 region = get_or_create_region(cache_region, cache_namespace_uid)
266 266 cache_keys = region.backend.list_keys(prefix=cache_namespace_uid)
267 267 num_delete_keys = len(cache_keys)
268 if num_delete_keys:
269 region.delete_multi(cache_keys)
268 if invalidate:
269 region.invalidate(hard=False)
270 else:
271 if num_delete_keys:
272 region.delete_multi(cache_keys)
270 273 return num_delete_keys
271 274
272 275
@@ -285,7 +285,8 b' class ScmModel(BaseModel):'
285 285 repo.update_commit_cache(config=config, cs_cache=None)
286 286 if delete:
287 287 cache_namespace_uid = 'cache_repo.{}'.format(repo_id)
288 rc_cache.clear_cache_namespace('cache_repo', cache_namespace_uid)
288 rc_cache.clear_cache_namespace(
289 'cache_repo', cache_namespace_uid, invalidate=True)
289 290
290 291 def toggle_following_repo(self, follow_repo_id, user_id):
291 292
General Comments 0
You need to be logged in to leave comments. Login now