Previous: , Up: Cache   [Contents]

22.2 Cache APIs

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:

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)))