Skip to content

Commit

Permalink
fix: use protobuf instead of gob
Browse files Browse the repository at this point in the history
  • Loading branch information
darkweak committed Aug 14, 2024
1 parent d01c621 commit 9301a77
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
8 changes: 5 additions & 3 deletions pkg/api/souin.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,12 @@ func (s *SouinAPI) BulkDelete(key string, purge bool) {
mapping.Mapping[k] = v
}

buf := bytes.NewBuffer([]byte{})
if gob.NewEncoder(buf).Encode(mapping) == nil {
_ = current.Set(core.MappingKeyPrefix+key, buf.Bytes(), 0)
v, e := proto.Marshal(&mapping)
if e != nil {
fmt.Println("Impossible to re-encode the mapping", core.MappingKeyPrefix+key)
current.Delete(core.MappingKeyPrefix + key)
}
_ = current.Set(core.MappingKeyPrefix+key, v, storageToInfiniteTTLMap[current.Name()])
}
}

Expand Down
10 changes: 1 addition & 9 deletions plugins/caddy/httpcache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1034,15 +1034,7 @@ func TestExpires(t *testing.T) {
}
}

cacheChecker(caddyTester, "/expires-only", "Hello, expires-only!", int(expiresValue.Sub(time.Now()).Seconds())-1)
cacheChecker(caddyTester, "/expires-only", "Hello, expires-only!", int(time.Until(expiresValue)-1))
cacheChecker(caddyTester, "/expires-with-max-age", "Hello, expires-with-max-age!", 59)
cacheChecker(caddyTester, "/expires-with-s-maxage", "Hello, expires-with-s-maxage!", 4)
}

type testCancelHandler struct{}

func (t *testCancelHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
fmt.Println("Request")
time.Sleep(time.Second)
_, _ = w.Write([]byte("Hello, cancel-handler!"))
}

0 comments on commit 9301a77

Please sign in to comment.