Caching X-Cache-Status总是使用代理缓存插件绕过
我在香港有服务,我已经为该服务设置了代理缓存插件Caching X-Cache-Status总是使用代理缓存插件绕过,caching,redis,kong,kong-plugin,Caching,Redis,Kong,Kong Plugin,我在香港有服务,我已经为该服务设置了代理缓存插件 curl-X POSThttp://localhost:8001/plugins --数据“name=proxy cache”--数据“config.strategy=redis”--数据“service_id=2f0a285d-7b25-48d6-adc3-bbf28ffe5f47”--数据“config.redis.host=127.0.0.1”--数据“config.redis.port=6379”--数据“config.redis.pas
curl-X POSThttp://localhost:8001/plugins --数据“name=proxy cache”--数据“config.strategy=redis”--数据“service_id=2f0a285d-7b25-48d6-adc3-bbf28ffe5f47”--数据“config.redis.host=127.0.0.1”--数据“config.redis.port=6379”--数据“config.redis.password=my_redis_password”
当我从该服务调用API时:
curl-i-xget--urlhttp://localhost:3002/v1/currency --标题“API密钥:我的API密钥”
一切正常,但X-Cache-Status始终处于旁路状态
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Content-Length: 3654
Connection: keep-alive
X-RateLimit-Limit-second: 100
X-RateLimit-Remaining-second: 99
X-Cache-Key: 3e18cdfc6e02359fb0f874efdf5788d8
X-Cache-Status: Bypass
X-Powered-By: Express
...
如何调试绕过原因?要避免在X-Cache-Status中绕过,您必须在创建代理缓存插件时添加此配置
--data "config.content_type=application/json; charset=utf-8"
香港社区版附带的插件
代理缓存
,只允许内存缓存。如果您想使用Redis进行缓存,则必须使用Kong Enterprise版本。更多信息
另一种选择是,在上提供一个名为kong-plugin-proxy-cache
的开源插件。您必须首先从Luarock安装插件,然后在Kong config中启用插件
# Install plugin dependency
sudo luarocks install lua-resty-redis-connector
# install plugin
sudo luarocks install kong-plugin-proxy-cache
# Enable plugin in kong.conf
plugins = bundled,proxy-cache
# After enabling, you can use plugin with any service, route or consumer.
# To enable it for a service
curl -X POST http://localhost:8001/services/<service-name>/plugins \
--data "name=proxy-cache" \
--data "config.cache_ttl=300" \
--data "config.cache_control=false" \
--data "config.redis.host=<redis-host>" \
--data "config.redis.port=<redis-port>"
#安装插件依赖项
sudo Luarock安装lua resty redis连接器
#安装插件
sudoluarocks安装插件代理缓存
#在kong.conf中启用插件
插件=捆绑,代理缓存
#启用后,您可以将插件用于任何服务、路由或消费者。
#为服务启用它
curl-X柱http://localhost:8001/services//plugins \
--数据“名称=代理缓存”\
--数据“config.cache\u ttl=300”\
--数据“config.cache\u control=false”\
--数据“config.redis.host=”\
--数据“config.redis.port=”