2020-06-23 03:11:56 +02:00
|
|
|
package middleware
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
2020-08-31 01:07:20 +02:00
|
|
|
"strconv"
|
2020-06-23 03:11:56 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
//DisableCache writes the disable cache header on the responses
|
2020-08-31 01:07:20 +02:00
|
|
|
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)
|
2020-06-23 03:11:56 +02:00
|
|
|
}
|