Created
October 21, 2020 13:38
-
-
Save haproxytechblog/c36b02678c5449b9f0876af3d15c4774 to your computer and use it in GitHub Desktop.
Accelerate Your APIs by Using the HAProxy Cache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
global | |
# global settings | |
defaults | |
# default settings | |
cache mycache | |
total-max-size 4095 # MB | |
max-object-size 10000 # bytes | |
max-age 30 # seconds |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
http-request cache-use api_cache if { path_beg /api/news_feed/ } | |
http-response cache-store api_cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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