Skip to content

Commit

Permalink
fix: 修复缓存数据存在后不会被刷新的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
helloplhm-qwq committed Jan 19, 2024
1 parent 863529f commit cff11e6
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions common/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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('缓存写入遇到错误…')
Expand Down

0 comments on commit cff11e6

Please sign in to comment.