From 361c87d6f055c18b58006b1721a559626296856f Mon Sep 17 00:00:00 2001
From: Akira Tempaku <paku@skyizwhite.dev>
Date: Sat, 21 Jun 2025 13:13:59 +0900
Subject: [PATCH] Improve set-cache

---
 src/app.lisp    | 10 ----------
 src/helper.lisp | 11 ++++++++++-
 2 files changed, 10 insertions(+), 11 deletions(-)

diff --git a/src/app.lisp b/src/app.lisp
index 6e85b2e..0c4f79d 100644
--- a/src/app.lisp
+++ b/src/app.lisp
@@ -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"
diff --git a/src/helper.lisp b/src/helper.lisp
index d2fe236..26b1d30 100644
--- a/src/helper.lisp
+++ b/src/helper.lisp
@@ -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"))))