openresty / openresty/srcache-nginx-module

$srcache_expire is always empty

Open
#61 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C
Stars
486
Forks
101
Avg merge
1h 28m
Merged PRs (30d)
2

Description

Hey!

I have been trying srcache with redis for few weeks now and today I noticed that the cache keys are not expiring automatically.

I'm using this config in local docker environment:

##
# Adds internal locations for storing and getting full page cache from redis
##

srcache_default_expire 10s;
srcache_max_expire 10s;

location /redis-fetch {
    internal;

    ##
    # In order to use password authentication we use custom redis module which adds $redis_auth:
    # - https://github.com/Yongke/ngx_http_redis-0.3.7
    ##

    # Read the configuration from system envs
    set $redis_auth '';
    set $redis_db 0;

    set $redis_key $args;

    redis_pass 172.17.0.6:6379;
}

location /redis-store {
    internal;

    set_unescape_uri $exptime $arg_exptime;
    set_unescape_uri $key $arg_key;

    # redis module pipelines these 3 commands into single request
    redis2_query auth '';
    redis2_query select 0;
    redis2_query set $key $echo_request_body;
    redis2_query expire $key $srcache_expire;

    # Pass the request to redis
    redis2_pass 172.17.0.6:6379;

}

Then I open redis-cli to monitor incoming requests:

$ redis-cli
> monitor
1478704802.63890 [0 172.17.0.8:54906] "select" "0"
1478704802.638100 [0 172.17.0.8:54906] "get" "wp_:nginx:httpsGETwordpress.test/robots.txt"
1478704802.638122 [0 172.17.0.8:54900] "auth" ""
1478704802.638137 [0 172.17.0.8:54900] "select" "0"
1478704802.638148 [0 172.17.0.8:54900] "set" "wp_:nginx:httpsGETwordpress.test/robots.txt" "HTTP/1.1 200 OK\r\nContent-Type: text/plain; charset=utf-8\r\nExpires: Thu, 19 Nov 1981 08:52:00 GMT\r\nCache-Control: no-store, no-cache, must-revalidate\r\nPragma: no-cache\r\nX-Robots-Tag: noindex, follow\r\nLink: <https://wordpress.test/wp-json/>; rel=\"https://api.w.org/\"\r\nLink: <https://wordpress.test/wp-json>; rel=\"https://github.com/WP-API/WP-API\"\r\nX-Cache: MISS\r\n\r\nUser-agent: *\nDisallow: /wp-admin/\nAllow: /wp-admin/admin-ajax.php\n"
1478704802.638189 [0 172.17.0.8:54900] "expire" "wp_:nginx:httpsGETwordpress.test/robots.txt" ""

And where I should see 10s because of the srcache_max_expire directive or 0 because of the Cache-Control: no-store, no-cache, must-revalidate header instead I see "" as sent to redis.

Version:

nginx -V
nginx version: openresty/1.11.2.1
built by gcc 4.9.2 (Debian 4.9.2-10)
built with OpenSSL 1.0.2j  26 Sep 2016
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx/nginx --with-cc-opt=-O2 --add-module=../ngx_devel_kit-0.3.0 --add-module=../echo-nginx-module-0.60 --add-module=../xss-nginx-module-0.05 --add-module=../ngx_coolkit-0.2rc3 --add-module=../set-misc-nginx-module-0.31 --add-module=../form-input-nginx-module-0.12 --add-module=../encrypted-session-nginx-module-0.06 --add-module=../srcache-nginx-module-0.31 --add-module=../ngx_lua-0.10.6 --add-module=../ngx_lua_upstream-0.06 --add-module=../headers-more-nginx-module-0.31 --add-module=../array-var-nginx-module-0.05 --add-module=../memc-nginx-module-0.17 --add-module=../redis2-nginx-module-0.13 --add-module=../rds-json-nginx-module-0.14 --add-module=../rds-csv-nginx-module-0.07 --with-ld-opt=-Wl,-rpath,/etc/nginx/luajit/lib --with-http_addition_module --with-http_auth_request_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-http_geoip_module=dynamic --with-file-aio --with-ipv6 --with-pcre-jit --with-stream --with-stream_ssl_module --with-threads --without-http_autoindex_module --without-http_browser_module --without-http_userid_module --without-mail_pop3_module --without-mail_imap_module --without-mail_smtp_module --without-http_split_clients_module --without-http_uwsgi_module --without-http_scgi_module --without-http_referer_module --user=nginx --group=nginx --sbin-path=/usr/sbin --modules-path=/usr/lib/nginx --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx/nginx.lock --http-fastcgi-temp-path=/tmp/nginx/fastcgi --http-proxy-temp-path=/tmp/nginx/proxy --http-client-body-temp-path=/tmp/nginx/client_body --add-module=/tmp/ngx_http_redis-0.3.7-master --add-module=/tmp/ngx_pagespeed-1.11.33.4-beta --with-openssl=/tmp/openssl-1.0.2j

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the configuration shown for the /redis-store location and inspect how the srcache_expire variable is populated before the redis2_query expire command runs. Compare the observed Redis MONITOR output with the configured expiry directives and response headers; done means the expiry value is correctly determined or the issue is documented as a configuration interaction.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, nginx, redis
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.