Skip to content

Instantly share code, notes, and snippets.

@lusis lusis/cache_test.t
Created Nov 3, 2016

What would you like to do?
Test::Nginx to validate cache behaviour
use Test::Nginx::Socket 'no_plan';
no warnings;
=== TEST 3: test_proxy_cache
--- http_config
proxy_cache_path /tmp/cache levels=1:2 use_temp_path=on keys_zone=auth_cache:10m;
upstream cluster {
# the following will only work if you're using the upstream health check module
# comment the next three lines out if not
check interval=3000 rise=1 fall=1 timeout=1000 type=http default_down=false;
check_http_send "GET /up HTTP/1.0\r\n\r\n";
check_http_expect_alive http_2xx http_3xx;
server {
location /up {
echo up;
location / {
auth_basic "Restricted";
auth_basic_user_file /t/htpasswd;
echo $remote_user;
--- config
location /auth {
proxy_cache_key "$http_authorization:$scheme:$proxy_host:$request_uri";
proxy_cache auth_cache;
proxy_cache_valid any 15s;
add_header X-Cache-Status $upstream_cache_status;
proxy_cache_methods GET;
proxy_pass http://cluster;
--- more_headers eval
["Authorization: Basic dXNlcjE6dXNlcjFwYXNz",
"Authorization: Basic dXNlcjE6dXNlcjFwYXNz",
"Authorization: Basic dXNlcjE6dXNlcjFwYXNz",
"Authorization: Basic dXNlcjE6dXNlcjFwYXNz",
"Authorization: Basic dXNlcjI6dXNlcjJwYXNz"]
--- request eval
["GET /auth",
"GET /auth",
"GET /auth",
"GET /auth",
"GET /auth"]
--- response_headers eval
["X-Cache-Status: MISS",
"X-Cache-Status: HIT",
"X-Cache-Status: HIT",
"X-Cache-Status: HIT",
"X-Cache-Status: MISS"]
--- response_body eval
--- error_code eval
["200", "200","200","200", "200"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.