Improve cache control
This commit is contained in:
parent
cc6683cdcc
commit
f16f49dde7
6 changed files with 33 additions and 13 deletions
|
@ -13,17 +13,28 @@
|
||||||
#:~layout))
|
#:~layout))
|
||||||
(in-package #:hp/renderer)
|
(in-package #:hp/renderer)
|
||||||
|
|
||||||
|
(defun set-cache-control (strategy)
|
||||||
|
(set-response-header :cache-control
|
||||||
|
(if (string= (hp-env) "dev")
|
||||||
|
"private, no-store"
|
||||||
|
(cond
|
||||||
|
((eq strategy :static)
|
||||||
|
"public, max-age=31536000, immutable")
|
||||||
|
((eq strategy :dynamic)
|
||||||
|
"public, max-age=60 stale-while-revalidate=86400, stale-if-error=86400")
|
||||||
|
(t
|
||||||
|
"private, no-store")))))
|
||||||
|
|
||||||
(defmethod jingle:process-response ((app jingle:app) result)
|
(defmethod jingle:process-response ((app jingle:app) result)
|
||||||
(set-response-header :content-type "text/html; charset=utf-8")
|
(set-response-header :content-type "text/html; charset=utf-8")
|
||||||
(set-response-header :cache-control (if (string= (hp-env) "dev")
|
|
||||||
"private, no-store"
|
|
||||||
"public, max-age=60 s-maxage=300, stale-while-revalidate=86400, stale-if-error=86400"))
|
|
||||||
(call-next-method app
|
(call-next-method app
|
||||||
(hsx:render-to-string
|
(hsx:render-to-string
|
||||||
(match result
|
(match result
|
||||||
((guard (or (list page metadata)
|
((plist :body body
|
||||||
page)
|
:metadata metadata
|
||||||
(typep page 'element))
|
:cache cache)
|
||||||
(~layout :metadata metadata
|
(progn
|
||||||
page))
|
(set-cache-control cache)
|
||||||
|
(~layout :metadata metadata
|
||||||
|
body)))
|
||||||
(_ (error "Invalid response form"))))))
|
(_ (error "Invalid response form"))))))
|
||||||
|
|
|
@ -15,4 +15,6 @@
|
||||||
|
|
||||||
(defun handle-get (params)
|
(defun handle-get (params)
|
||||||
(declare (ignore params))
|
(declare (ignore params))
|
||||||
(list (~page) *metadata*))
|
(list :body (~page)
|
||||||
|
:metadata *metadata*
|
||||||
|
:cache :dynamic))
|
||||||
|
|
|
@ -15,4 +15,6 @@
|
||||||
|
|
||||||
(defun handle-get (params)
|
(defun handle-get (params)
|
||||||
(declare (ignore params))
|
(declare (ignore params))
|
||||||
(list (~page) *metadata*))
|
(list :body (~page)
|
||||||
|
:metadata *metadata*
|
||||||
|
:cache :dynamic))
|
||||||
|
|
|
@ -28,4 +28,5 @@
|
||||||
|
|
||||||
(defun handle-get (params)
|
(defun handle-get (params)
|
||||||
(declare (ignore params))
|
(declare (ignore params))
|
||||||
(~page))
|
(list :body (~page)
|
||||||
|
:cache :static))
|
||||||
|
|
|
@ -18,4 +18,6 @@
|
||||||
"Back to TOP"))))
|
"Back to TOP"))))
|
||||||
|
|
||||||
(defun handle-not-found ()
|
(defun handle-not-found ()
|
||||||
(list (~page) *metadata*))
|
(list :body (~page)
|
||||||
|
:metadata *metadata*
|
||||||
|
:cache :dynamic))
|
||||||
|
|
|
@ -15,4 +15,6 @@
|
||||||
|
|
||||||
(defun handle-get (params)
|
(defun handle-get (params)
|
||||||
(declare (ignore params))
|
(declare (ignore params))
|
||||||
(list (~page) *metadata*))
|
(list :body (~page)
|
||||||
|
:metadata *metadata*
|
||||||
|
:cache :dynamic))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue