mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-11-09 03:50:27 +08:00
删除缓存的时同时删除相关的缓存(压缩格式、WebP格式、http和https互换URL)
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/caches"
|
"github.com/TeaOSLab/EdgeNode/internal/caches"
|
||||||
|
"github.com/TeaOSLab/EdgeNode/internal/compressions"
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/events"
|
"github.com/TeaOSLab/EdgeNode/internal/events"
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/goman"
|
"github.com/TeaOSLab/EdgeNode/internal/goman"
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/remotelogs"
|
"github.com/TeaOSLab/EdgeNode/internal/remotelogs"
|
||||||
@@ -18,6 +19,7 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -41,7 +43,7 @@ type HTTPCacheTaskManager struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewHTTPCacheTaskManager() *HTTPCacheTaskManager {
|
func NewHTTPCacheTaskManager() *HTTPCacheTaskManager {
|
||||||
var duration = 1 * time.Minute
|
var duration = 30 * time.Second
|
||||||
if Tea.IsTesting() {
|
if Tea.IsTesting() {
|
||||||
duration = 10 * time.Second
|
duration = 10 * time.Second
|
||||||
}
|
}
|
||||||
@@ -155,12 +157,41 @@ func (this *HTTPCacheTaskManager) processKey(key *pb.HTTPCacheTaskKey) error {
|
|||||||
for _, storage := range storages {
|
for _, storage := range storages {
|
||||||
switch key.KeyType {
|
switch key.KeyType {
|
||||||
case "key":
|
case "key":
|
||||||
err := storage.Purge([]string{key.Key}, "file")
|
var cacheKeys = []string{key.Key}
|
||||||
if err != nil {
|
if strings.HasPrefix(key.Key, "http://") {
|
||||||
return err
|
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":
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user