1

I have a registered service in Kong and currently trying to set up the proxy-cache plugin.

The plugin itself works fine when cache control is set to false, but when I enable it, the X-Cache-Status header is always Bypass.

The plugin configuration looks like this:

  plugins:
  - name: proxy-cache
    service: echo
    config: 
      response_code
      - 200
      - 301
      - 404
      request_method:
      - GET
      - HEAD
      content_type:
      - text/plain
      - application/json
      - application/json; charset=utf-8
      - text/plain; charset=utf-8
      cache_ttl: 300
      strategy: memory
      cache_control: true
      memory:
        dictionary_name: kong_db_cache

And the request looks like this:

curl --location --request GET 'http://localhost:8000/echo' --header 'Cache-Control: public, max-age=20'

I was experimenting with different Cache-Control values, registered also request-transformer plugin and was playing with headers there, but nothing seems to work.

Did anyone encounter this issue before? I'm pretty much stuck here and any kind of suggestion is more than welcome.

dixy
  • 13
  • 4

1 Answers1

0

You have set the option

cache_control: true

So Kong will respect the Cache-Control behaviors defined in RFC7234

You need to have an cache header into the upstream answer. Or you should set it to false

Ôrel
  • 7,044
  • 3
  • 27
  • 46
  • I did add this. That's the problem. If this is set to false, the plugin works fine, but when I set it to true, it's not working (and I need this to be set to true). Check my configuration and request example above. – dixy Dec 02 '21 at 13:15
  • If you want to set it to true your upstream should set control header, and you will have have cache – Ôrel Dec 02 '21 at 13:18
  • You mean in the response headers also? Because, I have it in request headers. – dixy Dec 02 '21 at 13:19
  • Thank you so much! I added the Cache-Control into response headers and it's working now. – dixy Dec 02 '21 at 13:37