diff --git a/src/renderer.lisp b/src/renderer.lisp index a6d826a..65e83d8 100644 --- a/src/renderer.lisp +++ b/src/renderer.lisp @@ -13,17 +13,28 @@ #:~layout)) (in-package #:hp/renderer) +(defun set-cache-control (strategy) + (set-response-header :cache-control + (if (string= (hp-env) "dev") + "private, no-store" + (cond + ((eq strategy :static) + "public, max-age=31536000, immutable") + ((eq strategy :dynamic) + "public, max-age=60 stale-while-revalidate=86400, stale-if-error=86400") + (t + "private, no-store"))))) + (defmethod jingle:process-response ((app jingle:app) result) (set-response-header :content-type "text/html; charset=utf-8") - (set-response-header :cache-control (if (string= (hp-env) "dev") - "private, no-store" - "public, max-age=60 s-maxage=300, stale-while-revalidate=86400, stale-if-error=86400")) (call-next-method app (hsx:render-to-string (match result - ((guard (or (list page metadata) - page) - (typep page 'element)) - (~layout :metadata metadata - page)) + ((plist :body body + :metadata metadata + :cache cache) + (progn + (set-cache-control cache) + (~layout :metadata metadata + body))) (_ (error "Invalid response form")))))) diff --git a/src/routes/bio.lisp b/src/routes/bio.lisp index 5002a65..e12e000 100644 --- a/src/routes/bio.lisp +++ b/src/routes/bio.lisp @@ -15,4 +15,6 @@ (defun handle-get (params) (declare (ignore params)) - (list (~page) *metadata*)) + (list :body (~page) + :metadata *metadata* + :cache :dynamic)) diff --git a/src/routes/blog.lisp b/src/routes/blog.lisp index 5760d3e..173a2ed 100644 --- a/src/routes/blog.lisp +++ b/src/routes/blog.lisp @@ -15,4 +15,6 @@ (defun handle-get (params) (declare (ignore params)) - (list (~page) *metadata*)) + (list :body (~page) + :metadata *metadata* + :cache :dynamic)) diff --git a/src/routes/index.lisp b/src/routes/index.lisp index 2c71a43..683ccc1 100644 --- a/src/routes/index.lisp +++ b/src/routes/index.lisp @@ -28,4 +28,5 @@ (defun handle-get (params) (declare (ignore params)) - (~page)) + (list :body (~page) + :cache :static)) diff --git a/src/routes/not-found.lisp b/src/routes/not-found.lisp index b05f179..34c3e21 100644 --- a/src/routes/not-found.lisp +++ b/src/routes/not-found.lisp @@ -18,4 +18,6 @@ "Back to TOP")))) (defun handle-not-found () - (list (~page) *metadata*)) + (list :body (~page) + :metadata *metadata* + :cache :dynamic)) diff --git a/src/routes/work.lisp b/src/routes/work.lisp index b538b06..9345a53 100644 --- a/src/routes/work.lisp +++ b/src/routes/work.lisp @@ -15,4 +15,6 @@ (defun handle-get (params) (declare (ignore params)) - (list (~page) *metadata*)) + (list :body (~page) + :metadata *metadata* + :cache :dynamic))