Skip to content

Commit

Permalink
Surrogate_keys enhancement
Browse files Browse the repository at this point in the history
  • Loading branch information
darkweak committed Jun 18, 2022
1 parent 4a54df5 commit 17c29c8
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion cache/surrogate/providers/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ func (s *baseStorage) storeTag(tag string, cacheKey string, re *regexp.Regexp) {
if currentValue, b := s.Storage[tag]; s.dynamic || b {
if !re.MatchString(currentValue) {
s.Storage[tag] = currentValue + souinStorageSeparator + cacheKey
s.Storage[stalePrefix+tag] = currentValue + souinStorageSeparator + stalePrefix + cacheKey
}
}
}
Expand Down Expand Up @@ -154,7 +153,9 @@ func (s *baseStorage) purgeTag(tag string) []string {
func (s *baseStorage) Store(response *http.Response, cacheKey string) error {
h := response.Header
quoted := regexp.QuoteMeta(souinStorageSeparator + cacheKey)
staleQuoted := regexp.QuoteMeta(souinStorageSeparator + cacheKey)
urlRegexp := regexp.MustCompile("(^" + regexp.QuoteMeta(cacheKey) + "(" + regexp.QuoteMeta(souinStorageSeparator) + "|$))|(" + quoted + ")|(" + quoted + "$)")
staleUrlRegexp := regexp.MustCompile("(^" + regexp.QuoteMeta(stalePrefix+cacheKey) + "(" + regexp.QuoteMeta(souinStorageSeparator) + "|$))|(" + staleQuoted + ")|(" + staleQuoted + "$)")

keys := s.ParseHeaders(s.parent.getSurrogateKey(h))

Expand All @@ -163,10 +164,12 @@ func (s *baseStorage) Store(response *http.Response, cacheKey string) error {
for _, control := range controls {
if s.parent.candidateStore(control) {
s.storeTag(key, cacheKey, urlRegexp)
s.storeTag(stalePrefix+key, stalePrefix+cacheKey, staleUrlRegexp)
}
}
} else {
s.storeTag(key, cacheKey, urlRegexp)
s.storeTag(stalePrefix+key, stalePrefix+cacheKey, staleUrlRegexp)
}
}

Expand Down

0 comments on commit 17c29c8

Please sign in to comment.