HAproxy and caching

  • Hello all,

    i m using haproxy-devel package (1.8.14-52e4d43) and i trying to use the cache feature of haproxy 1.8.

    i manage to add cache section in haproxy config file by editing /usr/local/pkg/haproxy.inc like in the example below.


    But i don't know how to verify if caching working.

    • Did someone successfully adding caching with HAproxy in pfsense ? (i ask my favorite search engine but i don t find many responses on this topic)
    • How can i access to HAproxy log of my backends ?

    Thanks for your help and sorry for my english ;)

  • @marn
    To verify if cache is working try running on a ssh/console this command:

    /usr/local/pkg/haproxy/haproxy_socket.sh show cache

    Don't edit haproxy.inc.

    Add the cache section to the 'Global Advanced pass thru' textbox.

    cache MyCache
      total-max-size 10
      max-age 60

    and add some cache items to the backend 'Backend pass thru':

    http-request cache-use MyCache if TRUE
    http-response cache-store MyCache if TRUE

    For a basic test that is.. For actual usage you should think about what acl's to apply before trying to use the cache for everything..

  • This post is deleted!

  • @piba Thank you

    I edited haproxy.inc because I thought cache section have to be in a separate section and not in global section. But you right, it works with "Global Advanced pass thru".

    My cache works well and change tune.bufsize variable to increase to number of cached files.

    @PiBa By managing my ACLs, you mean, choose to not cache admin page of my backend or something like that ?

    Why do you add a "if TRUE" at the end of "Backend pass thru" ? it doesn't appear in HAproxy manual. Does it mean the line are used if "MyCache" exist ?

    Long story: I m using docker to run several containers/services (nextcloud, wordpress, emby,...) on my server. HAproxy (on my router) is configured to redirect the request from different url to the right backend and ssl offload it.

    i want to cache requests to reduce the load of my server. I see Varnish can do it but i don't know why Varnish are not present in pfsense 2.4 packages. yet this package seems to exist on previous versions. So i try with HAproxy 1.8 ,but like i said, i don't see many post on caching ability of HAproxy.

  • @marn
    I just added "if TRUE" as an example for the capability to use 'if', but basically its not really useful written like that. It would make more sense to make something like cache-able stuff acl like this, but i choose to cut that a little short 😉 :

    http-request set-var(txn.MyPath) path
    acl WeCanSafelyCacheThatFile var(txn.MyPath) -m end .js .css
    http-request cache-use MyCache if WeCanSafelyCacheThatFile
    http-response cache-store MyCache if WeCanSafelyCacheThatFile

    Haproxy only recently gained the ability to cache files even small ones, and is really only meant to cache the really really simple and small stuff.. Willy called it a 'favicon cache' in one of his mails in its beginning. Though its abilities are growing. it will not become a full blown caching proxy anytime soon. Just yesterday a commit was added for 1.9dev to be able to cache items that are a bit larger than the size of a buffer.. And by using acl's you can make control what items are and are not cached.

  • @piba haha, i think i have to learn more about acls before asking questions ^^

    Thank for your help

Log in to reply