Previous: , Up: Cache   [Contents]

18.2 Cache APIs

You have to use #:cache mode while you defining URL rule handler.

(get "/certain-rule" #:cache mode
  (lambda (rc) ...))

NOTE: the default value of maxage is defined by cache.maxage in /etc/artanis/artanis.conf. The default value is 3600 seconds.

mode could be:

Let’s see the simplest cache test (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 "pub/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 "pub/some.html") ; will be changed to 'private' forcely.
  (lambda (rc) (:cache rc)))