diff --git a/src/renderer.lisp b/src/renderer.lisp index 6aa0d8d..61bb55a 100644 --- a/src/renderer.lisp +++ b/src/renderer.lisp @@ -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))) diff --git a/src/routes/about.lisp b/src/routes/about.lisp index 6e320c0..99ca377 100644 --- a/src/routes/about.lisp +++ b/src/routes/about.lisp @@ -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" diff --git a/src/routes/blog/<id>.lisp b/src/routes/blog/<id>.lisp index cd0d012..43d2d2a 100644 --- a/src/routes/blog/<id>.lisp +++ b/src/routes/blog/<id>.lisp @@ -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")) diff --git a/src/routes/blog/index.lisp b/src/routes/blog/index.lisp index 7953a7f..ff668c6 100644 --- a/src/routes/blog/index.lisp +++ b/src/routes/blog/index.lisp @@ -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 diff --git a/src/routes/index.lisp b/src/routes/index.lisp index a7863d5..663a7ae 100644 --- a/src/routes/index.lisp +++ b/src/routes/index.lisp @@ -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 diff --git a/src/routes/not-found.lisp b/src/routes/not-found.lisp index ef23176..dc6a623 100644 --- a/src/routes/not-found.lisp +++ b/src/routes/not-found.lisp @@ -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") diff --git a/src/routes/works.lisp b/src/routes/works.lisp index 570dce2..68da918 100644 --- a/src/routes/works.lisp +++ b/src/routes/works.lisp @@ -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"