Cache-control:max-age의 실험

6447 단어 Gogolang캐시tech

서버


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), 캐시 사용 가능
  • 좋은 웹페이지 즐겨찾기