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