You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
19 lines
507 B
19 lines
507 B
package middleware |
|
|
|
import ( |
|
"net/http" |
|
"strconv" |
|
) |
|
|
|
//DisableCache writes the disable cache header on the responses |
|
func DisableCache(w http.ResponseWriter) { |
|
w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate") |
|
w.Header().Set("Expires", "0") |
|
} |
|
|
|
//SetCache will set the cache control header of a response |
|
func SetCache(days int, w http.ResponseWriter) { |
|
seconds := strconv.Itoa(days * 86400) |
|
w.Header().Set("Cache-Control", "max-age="+seconds) |
|
w.Header().Set("Expires", seconds) |
|
}
|
|
|