0

My situation is: cache is enabled, lookups are happening but no cache hits.

This is my configuration:

cache cache-foo
  total-max-size 32
  max-object-size 1024
  max-age 120

backend foo_backend
  http-request cache-use cache-foo if { path_beg /api/ }
  server app1 10.116.0.1:80 check
  server app2 10.116.0.2:80 check
  server app3 10.116.0.3:80 check
  http-response cache-store cache-foo

I enabled the cache via dataplane. I can check that the cache is running by connecting to the socket and running show cache:

show cache
0x7f100f50a03a: cache-foo (shctx:0x7f100f50a000, available blocks:32768)

Running show stats I can see that there are about 50 "Cache Lookups" but 0 "Cache hits".

I assume that since I'm getting Lookups, that the cache data is being searched for, but somehow the cache is not being populated.

Could this be because of the order of the statements in the backend definition? If so, is there a way to change them via the dataplane-api?

edmz
  • 215
  • 2
  • 6

1 Answers1

0

HAProxy honors what the backend sends back in the Cache-Control header. In my case, a max-age of 0 was being sent, in this case causing HAProxy to skip the cache.

Changing the value to something greater than 0 will allow the cache of HAProxy to work. And that value will take precedence over what is specified in haproxy.cfg.

You can check that a response was served from cache because a header of age is returned.

edmz
  • 215
  • 2
  • 6