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))
|
||||
(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)
|
||||
(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
|
||||
(hsx:render-to-string
|
||||
(match result
|
||||
((guard (or (list page metadata)
|
||||
page)
|
||||
(typep page 'element))
|
||||
(~layout :metadata metadata
|
||||
page))
|
||||
((plist :body body
|
||||
:metadata metadata
|
||||
:cache cache)
|
||||
(progn
|
||||
(set-cache-control cache)
|
||||
(~layout :metadata metadata
|
||||
body)))
|
||||
(_ (error "Invalid response form"))))))
|
||||
|
|
|
@ -15,4 +15,6 @@
|
|||
|
||||
(defun handle-get (params)
|
||||
(declare (ignore params))
|
||||
(list (~page) *metadata*))
|
||||
(list :body (~page)
|
||||
:metadata *metadata*
|
||||
:cache :dynamic))
|
||||
|
|
|
@ -15,4 +15,6 @@
|
|||
|
||||
(defun handle-get (params)
|
||||
(declare (ignore params))
|
||||
(list (~page) *metadata*))
|
||||
(list :body (~page)
|
||||
:metadata *metadata*
|
||||
:cache :dynamic))
|
||||
|
|
|
@ -28,4 +28,5 @@
|
|||
|
||||
(defun handle-get (params)
|
||||
(declare (ignore params))
|
||||
(~page))
|
||||
(list :body (~page)
|
||||
:cache :static))
|
||||
|
|
|
@ -18,4 +18,6 @@
|
|||
"Back to TOP"))))
|
||||
|
||||
(defun handle-not-found ()
|
||||
(list (~page) *metadata*))
|
||||
(list :body (~page)
|
||||
:metadata *metadata*
|
||||
:cache :dynamic))
|
||||
|
|
|
@ -15,4 +15,6 @@
|
|||
|
||||
(defun handle-get (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