Improve set-cache

This commit is contained in:
Akira Tempaku 2025-06-21 13:13:59 +09:00
parent 96e7dadfdf
commit 361c87d6f0
Signed by: paku
GPG key ID: 5B4E8402BCC50607
2 changed files with 10 additions and 11 deletions

View file

@ -28,16 +28,6 @@
(defmethod jingle:process-response :around ((app (eql *page-app*)) result)
(set-response-header :content-type "text/html; charset=utf-8")
(when (eq (request-method *request*) :get)
(let ((strategy (context :cache)))
(cond ((dev-mode-p)
(set-response-header :cache-control "private, no-store, must-revalidate"))
((eq strategy :ssr)
(set-response-header :cache-control "public, max-age=0, must-revalidate"))
((eq strategy :isr)
(set-response-header :cache-control "public, max-age=0, s-maxage=60, stale-while-revalidate=60"))
((eq strategy :sg)
(set-response-header :cache-control "public, max-age=0, s-maxage=31536000, must-revalidate")))))
(call-next-method app
(render-to-string
(hsx (html :lang "en"

View file

@ -5,6 +5,8 @@
#:make-flexi-stream)
(:import-from #:jonathan
#:parse)
(:import-from #:website/lib/env
#:dev-mode-p)
(:export #:request-body-json->plist
#:set-metadata
#:set-cache))
@ -23,4 +25,11 @@
(setf (context :metadata) metadata))
(defun set-cache (strategy)
(setf (context :cache) strategy))
(cond ((dev-mode-p)
(set-response-header :cache-control "private, no-store, must-revalidate"))
((eq strategy :ssr)
(set-response-header :cache-control "public, max-age=0, must-revalidate"))
((eq strategy :isr)
(set-response-header :cache-control "public, max-age=0, s-maxage=60, stale-while-revalidate=60"))
((eq strategy :sg)
(set-response-header :cache-control "public, max-age=0, s-maxage=31536000, must-revalidate"))))