Cache-control:max-age의 실험
서버
goo 언어에 실험 서버 설치
package main
import (
"fmt"
"log"
"net/http"
"net/http/httputil"
)
func handler(w http.ResponseWriter, r *http.Request) {
// Cache-Control実験
w.Header().Add("Cache-Control", "max-age=180")
dump, err := httputil.DumpRequest(r, true)
if err != nil {
http.Error(w, fmt.Sprint(err), http.StatusInternalServerError)
return
}
fmt.Println(string(dump))
fmt.Fprintf(w, "<html><body>hello</body></html>")
}
func main() {
var httpServer http.Server
http.HandleFunc("/", handler)
log.Println("start http listening : 18888")
httpServer.Addr = ":18888"
log.Println(httpServer.ListenAndServe())
}
브라우저를 통해 액세스
브라우저에서 Chrom 사용(버전: 100.0.498.88)
처음 방문했을 때의 머리글
General
Request URL: http://localhost:18888/
Request Method: GET
Status Code: 200 OK
Remote Address: [::1]:18888
Referrer Policy: strict-origin-when-cross-origin
Response Header
Cache-Control: max-age=180
Content-Length: 31
Content-Type: text/html; charset=utf-8
Date: Thu, 21 Apr 2022 13:28:47 GMT
Request Header
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Accept-Encoding: gzip, deflate, br
Accept-Language: ja,en-US;q=0.9,en;q=0.8
Connection: keep-alive
Cookie: BetterErrors-has-used-console=true
Host: localhost:18888
sec-ch-ua: " Not A;Brand";v="99", "Chromium";v="100", "Google Chrome";v="100"
sec-ch-ua-mobile: ?0
sec-ch-ua-platform: "macOS"
Sec-Fetch-Dest: document
Sec-Fetch-Mode: navigate
Sec-Fetch-Site: none
Sec-Fetch-User: ?1
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36
두 번째 방문 시 머리글
General
Request URL: http://localhost:18888/
Request Method: GET
Status Code: 200 OK (from disk cache)
Remote Address: [::1]:18888
Referrer Policy: strict-origin-when-cross-origin
Response Header
Cache-Control: max-age=180
Content-Length: 31
Content-Type: text/html; charset=utf-8
Date: Thu, 21 Apr 2022 13:28:47 GMT
Status Code: 200 OK (from disk cache)
, 캐시 사용 가능Reference
이 문제에 관하여(Cache-control:max-age의 실험), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://zenn.dev/morris/articles/13d137ce6b4ea5텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)