Commit b4e939f3 authored by Michal Čihař's avatar Michal Čihař

Add method for cache clearing

Signed-off-by: default avatarMichal Čihař <michal@cihar.com>
parent 37f861ae
...@@ -23,11 +23,28 @@ Permissions abstract layer for Weblate. ...@@ -23,11 +23,28 @@ Permissions abstract layer for Weblate.
from weblate import appsettings from weblate import appsettings
from django.core.cache import cache from django.core.cache import cache
ALL_CACHES = set()
KEY_TEMPLATE = 'permission-{0}-{1}-{2}'
def clear_cache(user, translation):
"""
Helper to clear permissions cache.
"""
for key in ALL_CACHES:
cache.delete(
KEY_TEMPLATE.format(
key, user.id, translation.id
)
)
def cache_permission(func): def cache_permission(func):
""" """
Caching for permissions check. Caching for permissions check.
""" """
ALL_CACHES.add(func.__name__)
def wrapper(user, translation): def wrapper(user, translation):
if user is None: if user is None:
userid = 0 userid = 0
...@@ -37,7 +54,7 @@ def cache_permission(func): ...@@ -37,7 +54,7 @@ def cache_permission(func):
translationid = 0 translationid = 0
else: else:
translationid = translation.id translationid = translation.id
key = 'permission-{0}-{1}-{2}'.format( key = KEY_TEMPLATE.format(
func.__name__, userid, translationid func.__name__, userid, translationid
) )
result = cache.get(key) result = cache.get(key)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment