Skip to content

Commit

Permalink
feat: torrent detail api
Browse files Browse the repository at this point in the history
  • Loading branch information
Tohrusky committed Jul 24, 2024
1 parent 7fd97b7 commit d65c7e9
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
18 changes: 18 additions & 0 deletions internal/common/cache/clear.go
Original file line number Diff line number Diff line change
@@ -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)
}
2 changes: 2 additions & 0 deletions internal/service/torrent/delete.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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)
}
2 changes: 2 additions & 0 deletions internal/service/torrent/edit.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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)
}

0 comments on commit d65c7e9

Please sign in to comment.