Using the Cache API inside workers to ensure consistency for KV at specific edge location

Hi there,

I wanted to ask about an idea I had. I have an application that requires consistency on data currently stored in CF KV but only at the edge location that the user is requesting from. Essentially they enter some data, it gets stored in KV with a request to a CF worker, and then they reload the website, and currently it pulls the data from KV, which is often 1-30 seconds out dated.

I was thinking, could I use the Cache API to set this data as well in the cache and not have this consistency issue for that specific user?

Thank you,

Storing the user data temporary in the Local Cloudflare Cache could work yes but you need be aware that it will be not stored for a long period if it is just request 1 Time.
My experience is that the Local CloudFlare Cache is purged after about 5 Seconds is there is not much requests.

Better would be to Store the User Data in the Local Session Cache inside the Web Browser after successful insert into the KV.

That way way you have Consistency and you dont even need make Requests to the KV and the Worker as long the Webbrowser is not Closed.

For More info aboiut the Session Storage of the Webbrowser see here:

Thank you very much @seoworks. I can’t believe I didn’t think of this. Great suggestion!