This repository was archived by the owner on Nov 5, 2024. It is now read-only.
File tree Expand file tree Collapse file tree
teaweb/actions/default/cache Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -23,6 +23,8 @@ func (this *RunAction) Execute() error {
2323 switch this .Cmd {
2424 case "cache.refresh" :
2525 this .runCacheRefresh ()
26+ case "cache.clean" :
27+ this .runCacheClean ()
2628 }
2729 return nil
2830}
@@ -43,6 +45,9 @@ func (this *RunAction) runCacheRefresh() {
4345 manager := teacache .FindCachePolicyManager (filename )
4446 if manager == nil {
4547 manager = teacache .NewManagerFromConfig (policy )
48+ defer func () {
49+ _ = manager .Close ()
50+ }()
4651 }
4752 prefixes := this .Data .GetSlice ("prefixes" )
4853 prefixStrings := []string {}
@@ -51,7 +56,30 @@ func (this *RunAction) runCacheRefresh() {
5156 }
5257 _ , err := manager .DeletePrefixes (prefixStrings )
5358 if err != nil {
54- logs .Println ("[cluster][cache.refresh]delete prefixes" )
59+ logs .Println ("[cluster][cache.refresh]delete prefixes: " + err .Error ())
60+ return
61+ }
62+ }
63+
64+ // clean cache
65+ func (this * RunAction ) runCacheClean () {
66+ filename := this .Data .GetString ("filename" )
67+ policy := shared .NewCachePolicyFromFile (filename )
68+ if policy == nil {
69+ logs .Println ("[cluster][cache.clean]can not find policy with '" + filename + "'" )
70+ return
71+ }
72+
73+ manager := teacache .FindCachePolicyManager (filename )
74+ if manager == nil {
75+ manager = teacache .NewManagerFromConfig (policy )
76+ defer func () {
77+ _ = manager .Close ()
78+ }()
79+ }
80+ err := manager .Clean ()
81+ if err != nil {
82+ logs .Println ("[cluster][cache.clean]clean: " + err .Error ())
5583 return
5684 }
5785}
Original file line number Diff line number Diff line change @@ -2,8 +2,10 @@ package cache
22
33import (
44 "github.com/TeaWeb/code/teacache"
5+ "github.com/TeaWeb/code/teacluster"
56 "github.com/TeaWeb/code/teaconfigs/shared"
67 "github.com/TeaWeb/code/teaweb/actions/default/actionutils"
8+ "github.com/iwind/TeaGo/maps"
79)
810
911type CleanPolicyAction struct {
@@ -53,6 +55,17 @@ func (this *CleanPolicyAction) RunPost(params struct {
5355 this .Fail ()
5456 }
5557
58+ // 同步到集群
59+ action := new (teacluster.RunAction )
60+ action .Cmd = "cache.clean"
61+ action .Data = maps.Map {
62+ "filename" : params .Filename ,
63+ }
64+ err = teacluster .SharedManager .Write (action )
65+ if err != nil {
66+ this .Fail ("同步到集群失败:" + err .Error ())
67+ }
68+
5669 this .Data ["result" ] = "清理完成"
5770 this .Success ()
5871}
Original file line number Diff line number Diff line change @@ -75,7 +75,7 @@ func (this *RefreshPolicyAction) RunPost(params struct {
7575
7676 this .Data ["count" ] = count
7777
78- // 清除节点
78+ // 同步到集群
7979 action := new (teacluster.RunAction )
8080 action .Cmd = "cache.refresh"
8181 action .Data = maps.Map {
@@ -84,7 +84,7 @@ func (this *RefreshPolicyAction) RunPost(params struct {
8484 }
8585 err = teacluster .SharedManager .Write (action )
8686 if err != nil {
87- this .Fail ("刷新集群失败 :" + err .Error ())
87+ this .Fail ("同步到集群失败 :" + err .Error ())
8888 }
8989
9090 this .Success ()
You can’t perform that action at this time.
0 commit comments