feat: respect module_cache config for UAPI cache

This commit is contained in:
yumoqing 2026-05-29 17:59:26 +08:00
parent 4892a4e460
commit 77b4b14525

View File

@ -8,10 +8,23 @@ from appPublic.streamhttpclient import StreamHttpClient, liner
from appPublic.dictObject import DictObject from appPublic.dictObject import DictObject
from appPublic.log import debug, exception, error from appPublic.log import debug, exception, error
from appPublic.aes import aes_encode_b64 from appPublic.aes import aes_encode_b64
from appPublic.jsonConfig import getConfig
from ahserver.globalEnv import password_decode from ahserver.globalEnv import password_decode
from ahserver.serverenv import get_serverenv, ServerEnv from ahserver.serverenv import get_serverenv, ServerEnv
from random import randint from random import randint
def _cache_enabled():
"""Check if cache is enabled for uapi module in config.json"""
try:
config = getConfig()
module_cache = config.module_cache
if module_cache is None:
return True
return getattr(module_cache, 'uapi', True)
except Exception:
return True
async def get_deerer(upappid, callerid): async def get_deerer(upappid, callerid):
db = DBPools() db = DBPools()
dbname = get_dbname() dbname = get_dbname()
@ -69,6 +82,7 @@ class UAPIData:
async def get_apiusers(self, appid, orgid=None): async def get_apiusers(self, appid, orgid=None):
key = appid key = appid
if _cache_enabled():
d = self.org_users.get(key) d = self.org_users.get(key)
if d: if d:
return d return d
@ -122,6 +136,7 @@ where b.orgid = c.ownerid
async def get_api(self, appid, apiname): async def get_api(self, appid, apiname):
key = f'{appid}.{apiname}' key = f'{appid}.{apiname}'
if _cache_enabled():
api = self.apidata.get(key) api = self.apidata.get(key)
if api: if api:
return api return api