Skip to content
This repository has been archived by the owner on May 8, 2024. It is now read-only.

[gha] probe for all keys #362

Merged
merged 3 commits into from Apr 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
44 changes: 18 additions & 26 deletions internal/http_cache/ghacache/ghacache.go
Expand Up @@ -52,38 +52,30 @@ func (cache *GHACache) get(writer http.ResponseWriter, request *http.Request) {
keys := strings.Split(request.URL.Query().Get("keys"), ",")
version := request.URL.Query().Get("version")

// The first key is used for exact matching which we support
httpCacheURL := cache.httpCacheURL(keys[0], version)
for _, key := range keys {
httpCacheURL := cache.httpCacheURL(key, version)

resp, err := http.Head(httpCacheURL)
if err != nil {
fail(writer, request, http.StatusInternalServerError, "GHA cache failed to "+
"retrieve %q: %v", httpCacheURL, err)

return
}
resp, err := http.Head(httpCacheURL)
if err != nil {
fail(writer, request, http.StatusInternalServerError, "GHA cache failed to "+
"retrieve %q: %v", httpCacheURL, err)

if resp.StatusCode == http.StatusOK {
jsonResp := struct {
Key string `json:"cacheKey"`
URL string `json:"archiveLocation"`
}{
Key: keys[0],
URL: httpCacheURL,
return
}

render.JSON(writer, request, &jsonResp)
if resp.StatusCode == http.StatusOK {
jsonResp := struct {
Key string `json:"cacheKey"`
URL string `json:"archiveLocation"`
}{
Key: key,
URL: httpCacheURL,
}

return
}

// The rest of the keys are used for prefix matching
// (fallback mechanism) which we do not support
if len(keys[1:]) != 0 {
fail(writer, request, http.StatusNotFound, "GHA cache does not support prefix "+
"matching, was needed for (%v, %v)", keys, version)
render.JSON(writer, request, &jsonResp)

return
return
}
}

writer.WriteHeader(http.StatusNoContent)
Expand Down