cacheTtlByStatus not working as intended

Hi,

For some reason, when using cacheTtlByStatus, CF is caching our assets for way more than we ask it to.

Old code:

{
  cf: {
    cacheTtl: 2,
    cacheEverything: true
  }
}

new code:

{
  cf: {
    cacheTtlByStatus: {
      '200-299': 2
    },
    cacheEverything: true
  }
}

When using the new code, CF caches our assets for hours and not for 2s like it used to.

Two notes:

I know that its an enterprise users only feature. I am an enterprise user.

I have already managed to find the bug and I hope it will help others that encounter the same bug, as the docs don’t mention it.

The issue was that we only took in to consideration 2xx responses, however in many cases the origin will reply with a “304 not modified” response, which for some reason are being cached for 20 minutes, even though we don’t explicitly declare 3xx caching.

The solution was to change the code to:

{
  cf: {
    cacheTtlByStatus: {
      '200-399': 2
    },
    cacheEverything: true
  }
}

Note the change from 200-299 to 200-399

3 Likes