From eb47e3a08cc18bcf03db2ee2e8c278ca621775ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=A5=A5=E8=B6=85?= Date: Wed, 15 Jun 2022 12:54:56 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=E7=BC=93=E5=AD=98=E7=9A=84?= =?UTF-8?q?=E6=97=B6=E5=90=8C=E6=97=B6=E5=88=A0=E9=99=A4=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E7=9A=84=E7=BC=93=E5=AD=98=EF=BC=88=E5=8E=8B=E7=BC=A9=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F=E3=80=81WebP=E6=A0=BC=E5=BC=8F=E3=80=81http=E5=92=8Ch?= =?UTF-8?q?ttps=E4=BA=92=E6=8D=A2URL=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/nodes/http_cache_task_manager.go | 41 ++++++++++++++++++++--- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/internal/nodes/http_cache_task_manager.go b/internal/nodes/http_cache_task_manager.go index 74c300e..4223855 100644 --- a/internal/nodes/http_cache_task_manager.go +++ b/internal/nodes/http_cache_task_manager.go @@ -8,6 +8,7 @@ import ( "errors" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" "github.com/TeaOSLab/EdgeNode/internal/caches" + "github.com/TeaOSLab/EdgeNode/internal/compressions" "github.com/TeaOSLab/EdgeNode/internal/events" "github.com/TeaOSLab/EdgeNode/internal/goman" "github.com/TeaOSLab/EdgeNode/internal/remotelogs" @@ -18,6 +19,7 @@ import ( "net" "net/http" "regexp" + "strings" "time" ) @@ -41,7 +43,7 @@ type HTTPCacheTaskManager struct { } func NewHTTPCacheTaskManager() *HTTPCacheTaskManager { - var duration = 1 * time.Minute + var duration = 30 * time.Second if Tea.IsTesting() { duration = 10 * time.Second } @@ -155,12 +157,41 @@ func (this *HTTPCacheTaskManager) processKey(key *pb.HTTPCacheTaskKey) error { for _, storage := range storages { switch key.KeyType { case "key": - err := storage.Purge([]string{key.Key}, "file") - if err != nil { - return err + var cacheKeys = []string{key.Key} + if strings.HasPrefix(key.Key, "http://") { + cacheKeys = append(cacheKeys, strings.Replace(key.Key, "http://", "https://", 1)) + } else if strings.HasPrefix(key.Key, "https://") { + cacheKeys = append(cacheKeys, strings.Replace(key.Key, "https://", "http://", 1)) + } + + // TODO 提升效率 + for _, cacheKey := range cacheKeys { + var subKeys = []string{ + cacheKey, + cacheKey + caches.SuffixMethod + "HEAD", + cacheKey + caches.SuffixWebP, + cacheKey + caches.SuffixPartial, + } + // TODO 根据实际缓存的内容进行组合 + for _, encoding := range compressions.AllEncodings() { + subKeys = append(subKeys, cacheKey+caches.SuffixCompression+encoding) + subKeys = append(subKeys, cacheKey+caches.SuffixWebP+caches.SuffixCompression+encoding) + } + + err := storage.Purge(subKeys, "file") + if err != nil { + return err + } } case "prefix": - err := storage.Purge([]string{key.Key}, "dir") + var prefixes = []string{key.Key} + if strings.HasPrefix(key.Key, "http://") { + prefixes = append(prefixes, strings.Replace(key.Key, "http://", "https://", 1)) + } else if strings.HasPrefix(key.Key, "https://") { + prefixes = append(prefixes, strings.Replace(key.Key, "https://", "http://", 1)) + } + + err := storage.Purge(prefixes, "dir") if err != nil { return err }