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)) (module, key))
result = cursor.fetchone() result = cursor.fetchone()
print(result)
if result: if result:
cache_data = json.loads(result[0]) cache_data = json.loads(result[0])
cache_data["time"] = int(cache_data["time"])
if (not cache_data['expire']): if (not cache_data['expire']):
return cache_data return cache_data
if (int(time.time()) < cache_data['time']): if (int(time.time()) < int(cache_data['time'])):
return cache_data return cache_data
except: except:
pass pass
@ -389,17 +391,13 @@ def updateCache(module, key, data):
cursor.execute( cursor.execute(
"SELECT data FROM cache WHERE module=? AND key=?", (module, key)) "SELECT data FROM cache WHERE module=? AND key=?", (module, key))
result = cursor.fetchone() result = cursor.fetchone()
print(data)
if result: if result:
cache_data = json.loads(result[0]) cursor.execute(
if isinstance(cache_data, dict): "UPDATE cache SET data = ? WHERE module = ? AND key = ?", (json.dumps(data), module, key))
cache_data.update(data)
else:
logger.error(
f"Cache data for module '{module}' and key '{key}' is not a dictionary.")
else: else:
cursor.execute( cursor.execute(
"INSERT INTO cache (module, key, data) VALUES (?, ?, ?)", (module, key, json.dumps(data))) "INSERT INTO cache (module, key, data) VALUES (?, ?, ?)", (module, key, json.dumps(data)))
conn.commit() conn.commit()
except: except:
logger.error('缓存写入遇到错误…') logger.error('缓存写入遇到错误…')