Improve cache control
This commit is contained in:
parent
4e97cd8002
commit
8580db7e12
7 changed files with 17 additions and 7 deletions
|
@ -18,9 +18,15 @@
|
|||
|
||||
(defmethod jingle:process-response :around ((app jingle:app) result)
|
||||
(when (eq (request-method *request*) :get)
|
||||
(if (or (context :no-cache) (dev-mode-p))
|
||||
(set-response-header :cache-control "private, no-store, must-revalidate")
|
||||
(set-response-header :cache-control "public, max-age=60")))
|
||||
(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")))))
|
||||
(cond ((api-request-p)
|
||||
(set-response-header :content-type "application/json; charset=utf-8")
|
||||
(call-next-method app (to-json result)))
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
(defun handle-get (params)
|
||||
(setf (context :metadata) *metadata*)
|
||||
(with-request-params ((draft-key "draft-key" nil)) params
|
||||
(setf (context :no-cache) draft-key)
|
||||
(setf (context :cache) (if draft-key :ssr :isr))
|
||||
(let ((about (fetch-about :draft-key draft-key)))
|
||||
(~article
|
||||
:title "About"
|
||||
|
|
|
@ -14,10 +14,10 @@
|
|||
(defun handle-get (params)
|
||||
(with-request-params ((id :id nil)
|
||||
(draft-key "draft-key" nil)) params
|
||||
(setf (context :no-cache) draft-key)
|
||||
(let ((blog (fetch-blog-detail id :draft-key draft-key)))
|
||||
(unless blog
|
||||
(return-from handle-get (handle-not-found)))
|
||||
(setf (context :cache) (if draft-key :ssr :isr))
|
||||
(setf (context :metadata) (list :title (getf blog :title)
|
||||
:description (getf blog :description)
|
||||
:type "article"))
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
|
||||
(defun handle-get (params)
|
||||
(declare (ignore params))
|
||||
(setf (context :cache) :isr)
|
||||
(setf (context :metadata) *metadata*)
|
||||
(let ((blogs (fetch-blog-list :page 1)))
|
||||
(hsx
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
(defpackage #:website/routes/index
|
||||
(:use #:cl
|
||||
#:hsx
|
||||
#:access)
|
||||
#:access
|
||||
#:jingle)
|
||||
(:import-from #:website/lib/cms
|
||||
#:get-about)
|
||||
(:export #:handle-get
|
||||
|
@ -27,6 +28,7 @@
|
|||
|
||||
(defun handle-get (params)
|
||||
(declare (ignore params))
|
||||
(setf (context :cache) :sg)
|
||||
(hsx
|
||||
(div :class "flex flex-col items-center justify-center h-full"
|
||||
(img
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
|
||||
(defun handle-not-found ()
|
||||
(set-response-status :not-found)
|
||||
(setf (context :cache) :ssr)
|
||||
(setf (context :metadata) *metadata*)
|
||||
(if (api-request-p)
|
||||
'(:|message| "404 Not Found")
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
(defun handle-get (params)
|
||||
(setf (context :metadata) *metadata*)
|
||||
(with-request-params ((draft-key "draft-key" nil)) params
|
||||
(setf (context :no-cache) draft-key)
|
||||
(setf (context :cache) (if draft-key :ssr :isr))
|
||||
(let ((works (fetch-works :draft-key draft-key)))
|
||||
(~article
|
||||
:title "Works"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue