mirror of
https://github.com/qaiu/netdisk-fast-download.git
synced 2026-06-11 07:57:28 +00:00
fix: 添加缓存表定时清理任务,修复 cache_link_info 无限增长
- CacheManager 添加 cleanupExpiredCache() 方法删除过期缓存记录 - PostExecVerticle 注册每小时执行一次的定时清理任务 - 原实现只有读时惰性检查过期,过期记录永远不会被删除,长期运行后数据库持续膨胀
This commit is contained in:
@@ -200,6 +200,31 @@ public class CacheManager {
|
||||
return promise.future();
|
||||
}
|
||||
|
||||
/**
|
||||
* 清理过期缓存记录,防止数据库无限增长
|
||||
* @return 删除的行数
|
||||
*/
|
||||
public Future<Integer> cleanupExpiredCache() {
|
||||
String sql = "DELETE FROM cache_link_info WHERE expiration > 0 AND expiration < #{now}";
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("now", System.currentTimeMillis());
|
||||
Promise<Integer> promise = Promise.promise();
|
||||
SqlTemplate.forUpdate(jdbcPool, sql)
|
||||
.execute(params)
|
||||
.onSuccess(res -> {
|
||||
int deleted = res.rowCount();
|
||||
if (deleted > 0) {
|
||||
LOGGER.info("清理过期缓存记录 {} 条", deleted);
|
||||
}
|
||||
promise.complete(deleted);
|
||||
})
|
||||
.onFailure(e -> {
|
||||
LOGGER.error("清理过期缓存失败", e);
|
||||
promise.fail(e);
|
||||
});
|
||||
return promise.future();
|
||||
}
|
||||
|
||||
public Future<Map<String, Integer>> getShareKeyTotal(String shareKey) {
|
||||
String sql = """
|
||||
SELECT `share_key`, SUM(cache_hit_total) AS hit_total, SUM(api_parser_total) AS parser_total
|
||||
|
||||
Reference in New Issue
Block a user