Skip to content

Commit

Permalink
wip(surrogate): invalidate
Browse files Browse the repository at this point in the history
  • Loading branch information
darkweak committed Aug 18, 2024
1 parent 534c572 commit fa61769
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
2 changes: 2 additions & 0 deletions pkg/api/souin.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,12 @@ func (s *SouinAPI) BulkDelete(key string, purge bool) {
}

if purge {
fmt.Println("PURGE the key", core.MappingKeyPrefix+key)
current.Delete(core.MappingKeyPrefix + key)
}
}

fmt.Println("PURGE the key", key)
s.Delete(key)
}

Expand Down
3 changes: 3 additions & 0 deletions pkg/storage/defaultProvider.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package storage

import (
"bytes"
"fmt"
"net/http"
"regexp"
"strings"
Expand Down Expand Up @@ -56,6 +57,8 @@ func (provider *Default) MapKeys(prefix string) map[string]string {

return true
}

keys[key.(string)] = fmt.Sprint(value)
if v, ok := value.(*core.StorageMapper); ok {
for _, v := range v.Mapping {
if v.StaleTime.AsTime().After(now) {
Expand Down
10 changes: 7 additions & 3 deletions pkg/surrogate/providers/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,11 @@ func uniqueTag(values []string) []string {
}
if _, found := tmp[item]; !found {
tmp[item] = true
i, _ := url.QueryUnescape(item)
list = append(list, i)

if strings.Contains(item, "%3B") || strings.Contains(item, "%3A") {
item, _ = url.QueryUnescape(item)
}
list = append(list, item)
}
}

Expand Down Expand Up @@ -237,6 +240,7 @@ func (s *baseStorage) Store(response *http.Response, cacheKey, uri, basekey stri

urlRegexp = regexp.MustCompile("(^|" + regexp.QuoteMeta(souinStorageSeparator) + ")" + regexp.QuoteMeta(basekey) + "(" + regexp.QuoteMeta(souinStorageSeparator) + "|$)")
s.storeTag(uri, basekey, urlRegexp)
s.storeTag(uri, cacheKey, urlRegexp)

return nil
}
Expand Down Expand Up @@ -266,7 +270,7 @@ func (s *baseStorage) Invalidate(method string, headers http.Header) {

// List returns the stored keys associated to resources
func (s *baseStorage) List() map[string]string {
return s.Storage.MapKeys(surrogatePrefix)
return s.Storage.MapKeys("")
}

// Destruct method will shutdown properly the provider
Expand Down

0 comments on commit fa61769

Please sign in to comment.