Skip to content

Instantly share code, notes, and snippets.

@haproxytechblog
Created October 21, 2020 13:38
Show Gist options
  • Save haproxytechblog/c36b02678c5449b9f0876af3d15c4774 to your computer and use it in GitHub Desktop.
Save haproxytechblog/c36b02678c5449b9f0876af3d15c4774 to your computer and use it in GitHub Desktop.
Accelerate Your APIs by Using the HAProxy Cache
global
# global settings
defaults
# default settings
cache mycache
total-max-size 4095 # MB
max-object-size 10000 # bytes
max-age 30 # seconds
frontend fe_api
bind :80
default_backend be_api
backend be_api
# Get from cache / put in cache
http-request cache-use mycache
http-response cache-store mycache
# server list
server s1 172.25.0.10:8080 check
http-request cache-use api_cache if { path_beg /api/news_feed/ }
http-response cache-store api_cache
$ echo "show cache" | socat tcp-connect:127.0.0.1:9999 -
0x7fcad7c9603a: api_cache (shctx:0x7fcad7c96000, available blocks:4193280)
0x7fcad7c960c0 hash:3075548050 size:363 (1 blocks), refcount:0, expire:10
http-response set-header X-Cache-Status HIT if !{ srv_id -m found }
http-response set-header X-Cache-Status MISS if { srv_id -m found }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment