fix: rsa_key cache setting (#3610)

This commit is contained in:
shaohuzhang1 2025-07-15 17:21:18 +08:00 committed by GitHub
parent 2ead8b3ed2
commit 158bd2f43b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 2 deletions

View File

@ -6,9 +6,11 @@
@date2023/11/10 10:43 @date2023/11/10 10:43
@desc: @desc:
""" """
from django.core.cache import cache
from django.utils.translation import gettext as _ from django.utils.translation import gettext as _
from .listener_manage import * from .listener_manage import *
from ..constants.cache_version import Cache_Version
from ..db.sql_execute import update_execute from ..db.sql_execute import update_execute
update_document_status_sql = """ update_document_status_sql = """
@ -31,5 +33,7 @@ def run():
) )
# 更新文档状态 # 更新文档状态
update_execute(update_document_status_sql, []) update_execute(update_document_status_sql, [])
version, get_key = Cache_Version.SYSTEM.value
cache.delete(get_key(key='rsa_key'), version=version)
finally: finally:
un_lock('event_init') un_lock('event_init')

View File

@ -14,10 +14,11 @@ from Crypto.PublicKey import RSA
from django.core import cache from django.core import cache
from django.db.models import QuerySet from django.db.models import QuerySet
from common.constants.cache_version import Cache_Version
from system_manage.models import SystemSetting, SettingType from system_manage.models import SystemSetting, SettingType
lock = threading.Lock() lock = threading.Lock()
rsa_cache = cache.caches['default'] rsa_cache = cache.cache
cache_key = "rsa_key" cache_key = "rsa_key"
# 对密钥加密的密码 # 对密钥加密的密码
secret_code = "mac_kb_password" secret_code = "mac_kb_password"
@ -45,7 +46,8 @@ def get_key_pair():
if rsa_value is not None: if rsa_value is not None:
return rsa_value return rsa_value
rsa_value = get_key_pair_by_sql() rsa_value = get_key_pair_by_sql()
rsa_cache.set(cache_key, rsa_value) version, get_key = Cache_Version.SYSTEM.value
rsa_cache.set(get_key(key='rsa_key'), rsa_value, timeout=None, version=version)
return rsa_value return rsa_value