fix: 修复缓存数据存在后不会被刷新的问题

This commit is contained in:
helloplhm-qwq 2024-01-19 22:55:00 +08:00
parent 863529f4b0
commit cff11e69c4
No known key found for this signature in database
GPG Key ID: B7542212855B2C26

View File

@ -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('缓存写入遇到错误…')