mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-12-28 08:26:35 +08:00
增加edge-node cache.garbage命令用于清理垃圾缓存
This commit is contained in:
@@ -808,6 +808,36 @@ func (this *Node) listenSock() error {
|
||||
_ = cmd.Reply(&gosock.Command{Params: maps.Map{
|
||||
"stats": m,
|
||||
}})
|
||||
case "cache.garbage":
|
||||
var shouldDelete = maps.NewMap(cmd.Params).GetBool("delete")
|
||||
|
||||
var count = 0
|
||||
var sampleFiles = []string{}
|
||||
err := caches.SharedManager.ScanGarbageCaches(func(path string) error {
|
||||
count++
|
||||
if len(sampleFiles) < 10 {
|
||||
sampleFiles = append(sampleFiles, path)
|
||||
}
|
||||
|
||||
if shouldDelete {
|
||||
_ = os.Remove(path) // .cache
|
||||
_ = os.Remove(caches.PartialRangesFilePath(path)) // @range.cache
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
_ = cmd.Reply(&gosock.Command{Params: maps.Map{
|
||||
"isOk": false,
|
||||
"error": err.Error(),
|
||||
}})
|
||||
} else {
|
||||
_ = cmd.Reply(&gosock.Command{Params: maps.Map{
|
||||
"isOk": true,
|
||||
"count": count,
|
||||
"sampleFiles": sampleFiles,
|
||||
}})
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user