Dynamically setting value for proxy_cache_valid

947 views
Skip to first unread message

RJoshi

unread,
Feb 11, 2016, 6:33:08 PM2/11/16
to openresty-en
Is it possible to set a different value for proxy_cache_valid directive using Lua module?  I have a requirement to set different expire time per service.  
I tried below in Nginx.conf but gives error.

 set proxy_cache_value 1m;

proxy_cache_valid $proxy_cache_value;

Yichun Zhang (agentzh)

unread,
Feb 12, 2016, 11:47:18 AM2/12/16
to openresty-en
Hello!
IIRC, the proxy_cache_valid directive does not support nginx
variables. You can try patching the NGINX core to add the support (and
possibly proposing the patch to the nginx-devel mailing list too), or
wait for the upcoming cache_filter_by_lua* directives which support
custom Lua code to control the NGINX http cache on a per-request
basis.

Best regards,
-agentzh

Guilherme

unread,
Feb 12, 2016, 12:16:17 PM2/12/16
to openre...@googlegroups.com
RJoshi,

Alternatively, you could do something like this using named locations:

location @cache-1m {
    ...
    proxy_cache_valid 200 1m;
    proxy_pass ...

}

location @cache-10m {
    ...
    proxy_cache_valid 200 10m;
    proxy_pass ...

}

location @cache-default {
    ...
    proxy_cache_valid 200 1h;
    proxy_pass...
}

location / {

    access_by_lua_block {

        if service == 1 then
            ngx.exec("@cache-1m")
        elseif service == 2 then
            ngx.exec("@cache-10m")
        else
            ngx.exec("@cache-default")
        end

    }

}

Regards,

Guilherme


--
You received this message because you are subscribed to the Google Groups "openresty-en" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openresty-en...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Nikolaos Tsipas

unread,
Sep 14, 2017, 5:15:18 AM9/14/17
to openresty-en
Hello agentzh,

Is the cache_filter_by_lua* still on the roadmap? When is it expected to become available? 

Regards,
Nik

David Birdsong

unread,
Sep 14, 2017, 12:44:01 PM9/14/17
to openresty-en
On Thu, Sep 14, 2017 at 2:15 AM, Nikolaos Tsipas <nick...@gmail.com> wrote:
Hello agentzh,

Is the cache_filter_by_lua* still on the roadmap? When is it expected to become available? 

Will there be a cache_filter_by_lua_eviction or something similar that allows for a cosocket to fire when an object gets evicted for whatever reason?
 

Regards,
Nik


On Friday, February 12, 2016 at 4:47:18 PM UTC, agentzh wrote:
Hello!

On Thu, Feb 11, 2016 at 3:33 PM, RJoshi wrote:
> Is it possible to set a different value for proxy_cache_valid directive
> using Lua module?  I have a requirement to set different expire time per
> service.
> I tried below in Nginx.conf but gives error.
>
>  set proxy_cache_value 1m;
>
> proxy_cache_valid $proxy_cache_value;
>

IIRC, the proxy_cache_valid directive does not support nginx
variables. You can try patching the NGINX core to add the support (and
possibly proposing the patch to the nginx-devel mailing list too), or
wait for the upcoming cache_filter_by_lua* directives which support
custom Lua code to control the NGINX http cache on a per-request
basis.

Best regards,
-agentzh

--
You received this message because you are subscribed to the Google Groups "openresty-en" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openresty-en+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages