4

I have service in Kong and I have set proxy-cache plugin for that service.

curl -X POST http://localhost:8001/plugins --data "name=proxy-cache" --data "config.strategy=redis" --data 'service_id=2f0a285d-7b25-48d6-adc3-bbf28ffe5f47' --data "config.redis.host=127.0.0.1" --data "config.redis.port=6379" --data "config.redis.password=my_redis_password"

When I call an API from that service:

curl -i -X GET --url http://localhost:3002/v1/currency --header 'apikey: MY_API_KEY'

everything works correctly but X-Cache-Status is always Bypass

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
...

How can I debug Bypass reason?

Saeed.Torabzadeh
  • 121
  • 2
  • 10

2 Answers2

4

To avoid Bypass in X-Cache-Status you have to add this config when you create your proxy-cache plugin

--data "config.content_type=application/json; charset=utf-8" 
lberyouk
  • 119
  • 1
  • 4
0

The plugin proxy-cache that comes bundled with Kong community edition only allows in-memory caching. If you want to use Redis for caching, you will have to use Kong Enterprise version. More information here

As an alternative, there is a open source plugin called kong-plugin-proxy-cache available on Github. You will have to first install the plugin from Luarocks and then enable the plugin in 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>"

Deepak Sharma
  • 156
  • 1
  • 9