-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
request help: proxy-cache plugin, why the cache expiration time cannot be configured dynamically? #5453
Comments
can you show an actual scenario? AFAIK, the cache time is determined by the upstream service and APISIX determines the caching behaviour based on the cache time set by the upstream service, which is equivalent to a protocol. If APISIX breaks this protocol, it can become chaotic. |
The setting of the timeout period belongs to the behavior of the application layer. As an intermediate proxy layer, the gateway should be decoupled from the application layer, so I think there is no problem in letting the application layer set the timeout period. |
@tzssangglass @shuaijinchao |
When I worked in a CDN vendor, I made the proxy_cache_valid time/proxy_cache_ignore_header configurable via Lua. It requires modifying the Nginx itself. |
Hi @jagerzhang Currently You can modify the basic configuration to suit your needs. But it works globally. |
嗯嗯,这个全局设置我知道了~ 不过我还是挺希望APISIX能支持下动态设置过期时间,把这个特性作为插件的一个可配置参数来设置。 这个缓存时长设置在Nginx里面是可以动态设置的,希望可以参考下:http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_cache_valid |
@spacewander @shuaijinchao @tzssangglass 从APISIX的ngx模板来看,这里也是用的Nginx原生的 Line 624 in fa8a34f
在使用Nginx的时候
是非常灵活的,不过 |
Yes, if you want to do it, @spacewander way would be better, dynamic. |
這個issue有新的進展嗎? |
now we can use proxy-cache plugin: https://github.com/apache/apisix/blob/master/docs/zh/latest/plugins/proxy-cache.md |
Yes, 我目前也是用proxy-cache plugin, 但是我的需求跟 @jagerzhang 一樣, 希望每條不同的Rooute能有不同的cache ttl, 現在只能所有route都是同一個cache ttl時間 |
IMO, the plugin configuration is independent on different routes. |
|
Maybe that's why. If you think this is a bug, please submit an issue and give the full steps to reproduce it. |
So far, |
請教有什麼方法可以支持不同route 有不同時間的磁盤緩存 |
As explained above, it is not currently supported. |
I will work on it. Thanks |
Should I make the proxy-cache plugin support cache_ttl? |
Yes |
When I read the code of |
It uses nginx's proxy-cache |
So do I need to modify the config of Nginx and reload it in |
And I have another question: I modify the value of cache_ttl of proxy_cache to 1s in 'conf/default_config.yaml'. It doesn't work. |
Back from vacation.
No. We need to modify Nginx and control it via Lua so the config can take effect at the plugin level. |
Does it mean that we need to modify the source code of Nginx? |
Issue description
Nginx 的 proxy-cache 可以动态设置TTL,比如:
但是APISIX 文档提到:
The cache expiration time cannot be configured dynamically. The expiration time can only be set by the upstream response header Expires or Cache-Control, and the default cache expiration time is 10s if there is no Expires or Cache-Control in the upstream response header
意思是完全看后端的过期设置来定,否则就按config.yml 默认的cache_ttl,感觉不是那么灵活,是否可以开放下,让我们可以在路由里面自行设置缓存TTL,并可以强制缓存(Nginx的 proxy-cache 还支持proxy_ignore_headers 忽略后端缓存申明...)
补充:
我尝试增加一个 response-rewrite插件来改写 expires 和 Cache-Control:
然后测试发现虽然响应头部已经被改写了,但是缓存TTL并没有生效,还是10S就过期了,应该是这个response-rewrite的工作机制位于缓存之后,所以并不能影响到缓存的TTL设置。
Environment
apisix version
): 2.10.0The text was updated successfully, but these errors were encountered: