mirror of https://github.com/jumpserver/jumpserver
[Update] 修改cache policy 开关
parent
8bb82d168b
commit
9903adf71b
|
@ -378,6 +378,7 @@ defaults = {
|
||||||
'LOGIN_LOG_KEEP_DAYS': 90,
|
'LOGIN_LOG_KEEP_DAYS': 90,
|
||||||
'ASSETS_PERM_CACHE_TIME': 3600*24,
|
'ASSETS_PERM_CACHE_TIME': 3600*24,
|
||||||
'SECURITY_MFA_VERIFY_TTL': 3600,
|
'SECURITY_MFA_VERIFY_TTL': 3600,
|
||||||
|
'ASSETS_PERM_CACHE_ENABLE': False,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -610,6 +610,7 @@ EMAIL_SUFFIX = CONFIG.EMAIL_SUFFIX
|
||||||
LOGIN_LOG_KEEP_DAYS = CONFIG.LOGIN_LOG_KEEP_DAYS
|
LOGIN_LOG_KEEP_DAYS = CONFIG.LOGIN_LOG_KEEP_DAYS
|
||||||
|
|
||||||
# User or user group permission cache time, default 3600 seconds
|
# User or user group permission cache time, default 3600 seconds
|
||||||
|
ASSETS_PERM_CACHE_ENABLE = CONFIG.ASSETS_PERM_CACHE_ENABLE
|
||||||
ASSETS_PERM_CACHE_TIME = CONFIG.ASSETS_PERM_CACHE_TIME
|
ASSETS_PERM_CACHE_TIME = CONFIG.ASSETS_PERM_CACHE_TIME
|
||||||
|
|
||||||
# Asset user auth external backend, default AuthBook backend
|
# Asset user auth external backend, default AuthBook backend
|
||||||
|
|
|
@ -28,6 +28,8 @@ def get_etag(request, *args, **kwargs):
|
||||||
cache_policy = request.GET.get("cache_policy")
|
cache_policy = request.GET.get("cache_policy")
|
||||||
if cache_policy != '1':
|
if cache_policy != '1':
|
||||||
return None
|
return None
|
||||||
|
if not UserPermissionCacheMixin.CACHE_ENABLE:
|
||||||
|
return None
|
||||||
view = request.parser_context.get("view")
|
view = request.parser_context.get("view")
|
||||||
if not view:
|
if not view:
|
||||||
return None
|
return None
|
||||||
|
@ -38,6 +40,7 @@ def get_etag(request, *args, **kwargs):
|
||||||
class UserPermissionCacheMixin:
|
class UserPermissionCacheMixin:
|
||||||
cache_policy = '0'
|
cache_policy = '0'
|
||||||
RESP_CACHE_KEY = '_PERMISSION_RESPONSE_CACHE_V2_{}'
|
RESP_CACHE_KEY = '_PERMISSION_RESPONSE_CACHE_V2_{}'
|
||||||
|
CACHE_ENABLE = settings.ASSETS_PERM_CACHE_ENABLE
|
||||||
CACHE_TIME = settings.ASSETS_PERM_CACHE_TIME
|
CACHE_TIME = settings.ASSETS_PERM_CACHE_TIME
|
||||||
_object = None
|
_object = None
|
||||||
|
|
||||||
|
@ -111,7 +114,10 @@ class UserPermissionCacheMixin:
|
||||||
|
|
||||||
@method_decorator(condition(etag_func=get_etag))
|
@method_decorator(condition(etag_func=get_etag))
|
||||||
def get(self, request, *args, **kwargs):
|
def get(self, request, *args, **kwargs):
|
||||||
self.cache_policy = request.GET.get('cache_policy', '0')
|
if not self.CACHE_ENABLE:
|
||||||
|
self.cache_policy = '0'
|
||||||
|
else:
|
||||||
|
self.cache_policy = request.GET.get('cache_policy', '0')
|
||||||
|
|
||||||
obj = self._get_object()
|
obj = self._get_object()
|
||||||
if obj is None:
|
if obj is None:
|
||||||
|
|
Loading…
Reference in New Issue