gocover.io icon indicating copy to clipboard operation
gocover.io copied to clipboard

Cache-Control of badges should be no-cache

Open xiaq opened this issue 9 years ago • 2 comments
trafficstars

Currently there is a one-day long cache age, which makes badges often outdated:

~> curl -iL https://gocover.io/_badge/github.com/elves/elvish/edit/
HTTP/1.1 302 Found
Location: https://img.shields.io/badge/coverage-5.8%-red.svg?style=flat
Date: Tue, 16 Feb 2016 23:27:55 GMT
Content-Length: 84
Content-Type: text/html; charset=utf-8

HTTP/1.1 200 OK
Server: cloudflare-nginx
Date: Tue, 16 Feb 2016 23:27:55 GMT
Content-Type: image/svg+xml;charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Set-Cookie: __cfduid=d7d2c146340ec5f3a93ecab82fba5d7ce1455665275; expires=Wed, 15-Feb-17 23:27:55 GMT; path=/; domain=.shields.io; HttpOnly
Cache-Control: public, max-age=86400
Last-Modified: Tue, 16 Feb 2016 23:10:32 GMT
CF-Cache-Status: HIT
Expires: Wed, 17 Feb 2016 23:27:55 GMT
CF-RAY: 275d06a517192bc4-AMS

<svg xmlns="http://www.w3.org/2000/svg" width="103" height="20"><linearGradient id="b" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><mask id="a"><rect width="103" height="20" rx="3" fill="#fff"/></mask><g mask="url(#a)"><path fill="#555" d="M0 0h63v20H0z"/><path fill="#e05d44" d="M63 0h40v20H63z"/><path fill="url(#b)" d="M0 0h103v20H0z"/></g><g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11"><text x="31.5" y="15" fill="#010101" fill-opacity=".3">coverage</text><text x="31.5" y="14">coverage</text><text x="82" y="15" fill="#010101" fill-opacity=".3">5.8%</text><text x="82" y="14">5.8%</text></g></svg>

xiaq avatar Feb 16 '16 23:02 xiaq

Regarding stale badges, there is more to it than that: https://github.com/vieux/gocover.io/issues/3#issuecomment-44035463

nathany avatar Feb 18 '16 08:02 nathany

@nathany not sure if this helps, but on Go Report Card we store the badge assets in the repo and serve the images ourselves with "no-store, no-cache, must-revalidate":

https://github.com/gojp/goreportcard/blob/master/handlers/badge.go#L50

We pull the repo's grade from the cache. It looks like you're using Redis for caching the coverages (maybe I'm wrong though, I didn't look too hard), so you might be able to do something similar.

Feel free to copy/paste or whatever!

shawnps avatar Dec 01 '16 06:12 shawnps