From aa83c24e18369cbcc76f352e39a9e8b9349bc4e8 Mon Sep 17 00:00:00 2001 From: Hazork Date: Sat, 11 Sep 2021 13:03:41 -0300 Subject: [PATCH] docs: updated readme example --- README.md | 12 +++++++++--- docs/{readme.ts => readme-example.ts} | 12 +++++++++--- 2 files changed, 18 insertions(+), 6 deletions(-) rename docs/{readme.ts => readme-example.ts} (62%) diff --git a/README.md b/README.md index 78abc42..ac2316c 100644 --- a/README.md +++ b/README.md @@ -67,7 +67,7 @@ import { createCache, SessionCacheStorage } from 'axios-cache-interceptor'; const api = axios.create(); // Other axios instance with caching enabled -const cache = createCache(api, { +const cachedApi = createCache(api, { // Store values on window.sessionStorage storage: new SessionCacheStorage(), @@ -75,8 +75,14 @@ const cache = createCache(api, { interpretHeader: true }); -// Exactly the same as before -cache.get('http://example.com/'); +// Make a requests that's only cached if the response comes with success header +cachedApi.get('http://example.com/', { + cache: { + cachePredicate: { + containsHeaders: ['success'] + } + } +}); ```
diff --git a/docs/readme.ts b/docs/readme-example.ts similarity index 62% rename from docs/readme.ts rename to docs/readme-example.ts index d2fdc3f..a05786c 100644 --- a/docs/readme.ts +++ b/docs/readme-example.ts @@ -7,7 +7,7 @@ import { createCache, SessionCacheStorage } from '../src/index'; const api = axios.create(); // Other axios instance with caching enabled -const cache = createCache(api, { +const cachedApi = createCache(api, { // Store values on window.sessionStorage storage: new SessionCacheStorage(), @@ -15,5 +15,11 @@ const cache = createCache(api, { interpretHeader: true }); -// Exactly the same as before -cache.get('http://example.com/'); +// Make a requests that's only cached if the response comes with success header +cachedApi.get('http://example.com/', { + cache: { + cachePredicate: { + containsHeaders: ['success'] + } + } +});