From 1727cb1ccc403999138767190c40d6a5ea39f6ff Mon Sep 17 00:00:00 2001 From: Sarunas Tamasauskas Date: Wed, 2 Feb 2022 16:46:08 +0100 Subject: [PATCH 1/2] Fix caching example by using `.clone()` method The `.json()` cannot be resolved more than once for the same request --- examples/custom-caching/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/custom-caching/index.js b/examples/custom-caching/index.js index 3468d4cf..cbf9eea5 100644 --- a/examples/custom-caching/index.js +++ b/examples/custom-caching/index.js @@ -14,14 +14,14 @@ const client = prismic.createClient(endpoint, { if (cache.has(key)) { // If the cache contains a value for the key, return it - return cache.get(key); + return cache.get(key).clone(); } else { // Otherwise, make the network request const res = await fetch(url, options); if (res.ok) { // If the request was successful, save it to the cache - cache.set(key, res); + cache.set(key, res.clone()); } return res; From 15ea6f66c23c85bda8d909ad647eff424278b1a8 Mon Sep 17 00:00:00 2001 From: Sarunas Tamasauskas Date: Wed, 2 Feb 2022 16:54:43 +0100 Subject: [PATCH 2/2] Fix caching example by using `.clone()` method --- examples/with-express/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/with-express/index.js b/examples/with-express/index.js index a7f876dc..61f81406 100644 --- a/examples/with-express/index.js +++ b/examples/with-express/index.js @@ -16,14 +16,14 @@ const client = prismic.createClient(endpoint, { if (cache.has(key)) { // If the cache contains a value for the key, return it - return cache.get(key); + return cache.get(key).clone(); } else { // Otherwise, make the network request const res = await fetch(url, options); if (res.ok) { // If the request was successful, save it to the cache - cache.set(key, res); + cache.set(key, res.clone()); } return res;