Unable to make Cache API work [Resolved]

Hi there

I have created a small PoC that works with the cache API in the Web Workers.
As the documentation states, this would not work in the preview, but it doesn’t work in production for me neither.

Here is the PoC code I created and deployed as a worker:

My expected output would be, when I visit my url. I would get the same
Hello world from cache : <same-timestamp-value> .

But when I visit my url in several consecutive times (from the same machine, so I expect to be hitting (mostly) the same edge location. But I get outputs like this:

Hello world from cache : 1545739290062
Hello world from cache : 1545739297369
Hello world from cache : 1545739302372
Hello world from cache : 1545739306399
Hello world from cache : 1545739310753
Hello world from cache : 1545739315426
Hello world from cache : 1545739322463
Hello world from cache : 1545739325924
Hello world from cache : 1545739329513

Note : The cf-ray value seems to be updating constantly, except for the -MAD suffix (which I assume refers to MADRID as I am currently located in Spain.

None of the above values is recurring, so am I always hitting another edge location that it recreates a new response every time? Or is there a logical issue in my code? But I ran out of inspiration. Did I miss something from the docs?

Happy Holidays!

Hi @SegersIan,

It appears that we only allow valid, registered domain names to be used with the Cache API. This is unintended, and I’ve filed a bug report internally to see if we can relax this requirement.

Could you try using a registered domain name as myRequest and see if that works for you? I was able to make your script work on my zone just by changing www.myconstantvalue.com to www.example.com, though using an arbitrary subdomain of your own might be cleaner.

Harris

Hi @harris

I tried it now with a “registered” domain name. Seems to be working smooth now!

Thank You
Ian

1 Like