diff --git a/internal/common/cache/clear.go b/internal/common/cache/clear.go new file mode 100644 index 0000000..b8f41c3 --- /dev/null +++ b/internal/common/cache/clear.go @@ -0,0 +1,18 @@ +package cache + +import ( + "github.com/TensoRaws/NuxBT-Backend/module/cache" + "strconv" +) + +// ClearCacheByKeys 清除缓存 +func ClearCacheByKeys(keys ...string) { + c := cache.Cache + c.Del(keys...) +} + +// ClearTorrentDetailCacheByTorrentID 清除种子详情缓存 +func ClearTorrentDetailCacheByTorrentID(torrentID int32) { + key := "/api/v1/torrent/detail?torrent_id=" + strconv.Itoa(int(torrentID)) + ClearCacheByKeys(key) +} diff --git a/internal/service/torrent/delete.go b/internal/service/torrent/delete.go index 2ce46da..b3549f2 100644 --- a/internal/service/torrent/delete.go +++ b/internal/service/torrent/delete.go @@ -1,6 +1,7 @@ package torrent import ( + "github.com/TensoRaws/NuxBT-Backend/internal/common/cache" "github.com/TensoRaws/NuxBT-Backend/internal/common/db" "github.com/TensoRaws/NuxBT-Backend/module/code" "github.com/TensoRaws/NuxBT-Backend/module/log" @@ -29,6 +30,7 @@ func Delete(c *gin.Context) { } resp.OK(c) + cache.ClearTorrentDetailCacheByTorrentID(req.TorrentID) log.Logger.Infof("delete torrent success, torrent_id: %d", req.TorrentID) } diff --git a/internal/service/torrent/edit.go b/internal/service/torrent/edit.go index 821387b..d23f0f8 100644 --- a/internal/service/torrent/edit.go +++ b/internal/service/torrent/edit.go @@ -1,6 +1,7 @@ package torrent import ( + "github.com/TensoRaws/NuxBT-Backend/internal/common/cache" "github.com/TensoRaws/NuxBT-Backend/internal/common/db" "github.com/TensoRaws/NuxBT-Backend/module/code" "github.com/TensoRaws/NuxBT-Backend/module/log" @@ -63,6 +64,7 @@ func Edit(c *gin.Context) { } resp.OK(c) + cache.ClearTorrentDetailCacheByTorrentID(req.TorrentID) log.Logger.Infof("update torrent info success, torrent id: %v", req.TorrentID) }