Is it possible to cache JSON object in the service worker using Workers Cache API?
I tried cache.put method and according to the documentation with request as a String.
So according to the Cache API documentation on cache.put “Each method accepts a Request object or string value as its first parameter. If a string is passed, it will be interpreted as the URL for a new Request object” and I am making a response as
myResponse = new Response(myJSONObject,{"status" : 200 ,"headers":{"Cache-Control" : "max-age=10000" } })
cache.put("myObject", myResponse)
And I am trying to match the cache using this call.
let getCachedResponse = await cache.match("myObject",{ignoreMethod : true});
But I am unable to get this to work. Can somebody show any example if its possible to cache a JSON object through Cache API.