Improve set-cache
This commit is contained in:
parent
96e7dadfdf
commit
361c87d6f0
2 changed files with 10 additions and 11 deletions
10
src/app.lisp
10
src/app.lisp
|
@ -28,16 +28,6 @@
|
||||||
|
|
||||||
(defmethod jingle:process-response :around ((app (eql *page-app*)) result)
|
(defmethod jingle:process-response :around ((app (eql *page-app*)) result)
|
||||||
(set-response-header :content-type "text/html; charset=utf-8")
|
(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
|
(call-next-method app
|
||||||
(render-to-string
|
(render-to-string
|
||||||
(hsx (html :lang "en"
|
(hsx (html :lang "en"
|
||||||
|
|
|
@ -5,6 +5,8 @@
|
||||||
#:make-flexi-stream)
|
#:make-flexi-stream)
|
||||||
(:import-from #:jonathan
|
(:import-from #:jonathan
|
||||||
#:parse)
|
#:parse)
|
||||||
|
(:import-from #:website/lib/env
|
||||||
|
#:dev-mode-p)
|
||||||
(:export #:request-body-json->plist
|
(:export #:request-body-json->plist
|
||||||
#:set-metadata
|
#:set-metadata
|
||||||
#:set-cache))
|
#:set-cache))
|
||||||
|
@ -23,4 +25,11 @@
|
||||||
(setf (context :metadata) metadata))
|
(setf (context :metadata) metadata))
|
||||||
|
|
||||||
(defun set-cache (strategy)
|
(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"))))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue