Improve cache control

This commit is contained in:
Akira Tempaku 2025-05-01 00:37:46 +09:00
parent cc6683cdcc
commit f16f49dde7
Signed by: paku
GPG key ID: 5B4E8402BCC50607
6 changed files with 33 additions and 13 deletions

View file

@ -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"))))))

View file

@ -15,4 +15,6 @@
(defun handle-get (params)
(declare (ignore params))
(list (~page) *metadata*))
(list :body (~page)
:metadata *metadata*
:cache :dynamic))

View file

@ -15,4 +15,6 @@
(defun handle-get (params)
(declare (ignore params))
(list (~page) *metadata*))
(list :body (~page)
:metadata *metadata*
:cache :dynamic))

View file

@ -28,4 +28,5 @@
(defun handle-get (params)
(declare (ignore params))
(~page))
(list :body (~page)
:cache :static))

View file

@ -18,4 +18,6 @@
"Back to TOP"))))
(defun handle-not-found ()
(list (~page) *metadata*))
(list :body (~page)
:metadata *metadata*
:cache :dynamic))

View file

@ -15,4 +15,6 @@
(defun handle-get (params)
(declare (ignore params))
(list (~page) *metadata*))
(list :body (~page)
:metadata *metadata*
:cache :dynamic))