mirror of
https://github.com/MeoProject/lx-music-api-server.git
synced 2025-05-23 19:17:41 +08:00
fix: 修复缓存数据存在后不会被刷新的问题
This commit is contained in:
parent
863529f4b0
commit
cff11e69c4
@ -366,11 +366,13 @@ def getCache(module, key):
|
||||
(module, key))
|
||||
|
||||
result = cursor.fetchone()
|
||||
print(result)
|
||||
if result:
|
||||
cache_data = json.loads(result[0])
|
||||
cache_data["time"] = int(cache_data["time"])
|
||||
if (not cache_data['expire']):
|
||||
return cache_data
|
||||
if (int(time.time()) < cache_data['time']):
|
||||
if (int(time.time()) < int(cache_data['time'])):
|
||||
return cache_data
|
||||
except:
|
||||
pass
|
||||
@ -389,17 +391,13 @@ def updateCache(module, key, data):
|
||||
cursor.execute(
|
||||
"SELECT data FROM cache WHERE module=? AND key=?", (module, key))
|
||||
result = cursor.fetchone()
|
||||
print(data)
|
||||
if result:
|
||||
cache_data = json.loads(result[0])
|
||||
if isinstance(cache_data, dict):
|
||||
cache_data.update(data)
|
||||
else:
|
||||
logger.error(
|
||||
f"Cache data for module '{module}' and key '{key}' is not a dictionary.")
|
||||
cursor.execute(
|
||||
"UPDATE cache SET data = ? WHERE module = ? AND key = ?", (json.dumps(data), module, key))
|
||||
else:
|
||||
cursor.execute(
|
||||
"INSERT INTO cache (module, key, data) VALUES (?, ?, ?)", (module, key, json.dumps(data)))
|
||||
|
||||
conn.commit()
|
||||
except:
|
||||
logger.error('缓存写入遇到错误…')
|
||||
|
Loading…
x
Reference in New Issue
Block a user