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 92a3874
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
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
3 changes: 2 additions & 1 deletion pkg/surrogate/providers/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,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 +267,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 92a3874

Please sign in to comment.