Browse Source

Disable cache for dynamic pages

Vova Tkach 6 years ago
parent
commit
881fff4590
2 changed files with 6 additions and 0 deletions
  1. 4 0
      engine/wrapper/static.go
  2. 2 0
      engine/wrapper/wrapper.go

+ 4 - 0
engine/wrapper/static.go

@@ -115,6 +115,7 @@ func (e *Wrapper) printPageDefault() {
 		e.printTmplPageError(err)
 		return
 	}
+	(*e.W).Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
 	(*e.W).Header().Set("Content-Type", "text/html")
 	tmpl.Execute(*e.W, tmplDataAll{
 		System: e.tmplGetSystemData(),
@@ -137,6 +138,7 @@ func (e *Wrapper) printPage404() {
 		e.printTmplPageError(err)
 		return
 	}
+	(*e.W).Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
 	(*e.W).WriteHeader(http.StatusNotFound)
 	(*e.W).Header().Set("Content-Type", "text/html")
 	tmpl.Execute(*e.W, tmplDataAll{
@@ -147,12 +149,14 @@ func (e *Wrapper) printPage404() {
 func (e *Wrapper) printTmplPageError(perr error) {
 	tmpl, err := template.New("template").Parse(string(Templates.PageTmplError))
 	if err != nil {
+		(*e.W).Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
 		(*e.W).WriteHeader(http.StatusInternalServerError)
 		(*e.W).Header().Set("Content-Type", "text/html")
 		(*e.W).Write([]byte("<h1>Critical engine error!</h1>"))
 		(*e.W).Write([]byte("<h2>" + perr.Error() + "</h2>"))
 		return
 	}
+	(*e.W).Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
 	(*e.W).WriteHeader(http.StatusInternalServerError)
 	(*e.W).Header().Set("Content-Type", "text/html")
 	tmpl.Execute(*e.W, tmplDataAll{

+ 2 - 0
engine/wrapper/wrapper.go

@@ -194,6 +194,7 @@ func (e *Wrapper) TmplFrontEnd(tname string, data interface{}) bool {
 		e.printTmplPageError(err)
 		return true
 	}
+	(*e.W).Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
 	tmpl.Execute(*e.W, tmplDataAll{
 		System: e.tmplGetSystemData(),
 		Data:   data,
@@ -207,6 +208,7 @@ func (e *Wrapper) TmplBackEnd(tcont []byte, data interface{}) bool {
 		e.printTmplPageError(err)
 		return true
 	}
+	(*e.W).Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
 	tmpl.Execute(*e.W, tmplDataAll{
 		System: e.tmplGetSystemData(),
 		Data:   data,