Previous: On web caching, Up: Cache [Contents]
You can use #:cache mode to define a URL rule handler.
(get "/certain-rule" #:cache mode (lambda (rc) ...))
NOTE: the default value of "maxage" (3600 seconds) is defined by cache.maxage in /etc/artanis/artanis.conf.
mode can be:
#t to enable caching the page.
#f to disable caching the page explicitly. It’s the default value.
('static [maxage <- 3600]) to be used for static files. The URL rule must be a real path to a static file.
(filename [maxage <- 3600]) to cache a static file. This is useful when you don’t want to reveal the actual path of the static file, but use a fake URL for it.
('public filename [maxage <- 3600]) to allow proxies cache the content of specified static file. If HTTP authentication is required, responses are automatically set to "private".
('private filename [maxage <- 3600]) to not allow proxies cache the content of specified static file.
Let’s set a simple cache setting for dynamic content:
(get "/new" #:cache #t (lambda (rc) (:cache rc "hello world")))
If you want to cache a static file, and permit proxies cache the content:
(get "/hide" #:cache '(public "/some.html") (lambda (rc) (:cache rc)))
But, if your current URL rule is used for authentication (once you use #:auth), the cache will be changed to private even if you specify public.
(get "/pauth" #:auth `(basic ,(lambda (rc u p) (and (string=? u "nala") (string=? p "123")))) #:cache '(public "/some.html") ; will be changed to 'private' forcely. (lambda (rc) (:cache rc)))