Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix for issue 1423

* no longer rely on global variables for invalidating caches
  • Loading branch information...
commit 4fec4d9265007f644048811eade72718ed44fa58 1 parent 35f76b0
@kux authored
Showing with 19 additions and 11 deletions.
  1. +19 −11 cms/cache/permissions.py
View
30 cms/cache/permissions.py
@@ -2,19 +2,27 @@
from django.conf import settings
from django.core.cache import cache
-permission_cache_keys = []
-all_keys = []
+from django.contrib.auth.models import User
+
+PERMISSION_KEYS = [
+ 'can_change', 'can_add', 'can_delete',
+ 'can_change_advanced_settings', 'can_publish',
+ 'can_change_permissions', 'can_move_page',
+ 'can_moderate', 'can_view']
+
def get_cache_key(user, key):
return "%s:permission:%s:%s" % (
settings.CMS_CACHE_PREFIX, user.username, key)
+
def get_permission_cache(user, key):
"""
Helper for reading values from cache
"""
return cache.get(get_cache_key(user, key))
+
def set_permission_cache(user, key, value):
"""
Helper method for storing values in cache. Stores used keys so
@@ -22,20 +30,20 @@ def set_permission_cache(user, key, value):
"""
# store this key, so we can clean it when required
cache_key = get_cache_key(user, key)
-
- if not cache_key in all_keys:
- all_keys.append(cache_key)
- if not key in permission_cache_keys:
- permission_cache_keys.append(key)
cache.set(cache_key, value, settings.CMS_CACHE_DURATIONS['permissions'])
+
def clear_user_permission_cache(user):
"""
Cleans permission cache for given user.
"""
- for key in permission_cache_keys:
- cache.delete(get_cache_key(user, key))
+ for key in PERMISSION_KEYS:
+ cache.delete(get_cache_key(user, key))
+
def clear_permission_cache():
- for key in all_keys:
- cache.delete(key)
+ users = User.objects.filter(is_active=True)
+ for user in users:
+ for key in PERMISSION_KEYS:
+ cache_key = get_cache_key(user, key)
+ cache.delete(cache_key)
Please sign in to comment.
Something went wrong with that request. Please try again.