Skip to content

Commit

Permalink
add-cache-no-store (#86)
Browse files Browse the repository at this point in the history
* add-cache-no-store

* add changeset

* enter canary pre release mode
  • Loading branch information
dferber90 committed Apr 6, 2023
1 parent b990e41 commit becf6bf
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 13 deletions.
8 changes: 8 additions & 0 deletions .changeset/pre.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"mode": "pre",
"tag": "canary",
"initialVersions": {
"@vercel/edge-config": "0.1.5"
},
"changesets": []
}
5 changes: 5 additions & 0 deletions .changeset/rare-swans-vanish.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@vercel/edge-config': patch
---

add cache: no-store to fetch requests
17 changes: 14 additions & 3 deletions src/index.common.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,10 @@ describe.each([
expect(fetchMock).toHaveBeenCalledTimes(1);
expect(fetchMock).toHaveBeenCalledWith(
`${modifiedBaseUrl}/item/foo?version=1`,
{ headers: new Headers({ Authorization: 'Bearer token-2' }) },
{
headers: new Headers({ Authorization: 'Bearer token-2' }),
cache: 'no-store',
},
);
});
});
Expand All @@ -109,6 +112,7 @@ describe.each([
{
method: 'HEAD',
headers: new Headers({ Authorization: 'Bearer token-2' }),
cache: 'no-store',
},
);
});
Expand All @@ -125,7 +129,10 @@ describe.each([
expect(fetchMock).toHaveBeenCalledTimes(1);
expect(fetchMock).toHaveBeenCalledWith(
`${modifiedBaseUrl}/digest?version=1`,
{ headers: new Headers({ Authorization: 'Bearer token-2' }) },
{
headers: new Headers({ Authorization: 'Bearer token-2' }),
cache: 'no-store',
},
);
});
});
Expand Down Expand Up @@ -166,7 +173,10 @@ describe.each([
expect(fetchMock).toHaveBeenCalledTimes(2);
expect(fetchMock).toHaveBeenCalledWith(
`${modifiedBaseUrl}/item/foo?version=1`,
{ headers: new Headers({ Authorization: 'Bearer token-2' }) },
{
headers: new Headers({ Authorization: 'Bearer token-2' }),
cache: 'no-store',
},
);
expect(fetchMock).toHaveBeenCalledWith(
`${modifiedBaseUrl}/item/foo?version=1`,
Expand All @@ -175,6 +185,7 @@ describe.each([
Authorization: 'Bearer token-2',
'if-none-match': 'a',
}),
cache: 'no-store',
},
);
});
Expand Down
34 changes: 30 additions & 4 deletions src/index.edge.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ describe('default Edge Config', () => {
expect(fetchMock).toHaveBeenCalledTimes(1);
expect(fetchMock).toHaveBeenCalledWith(`${baseUrl}/item/foo?version=1`, {
headers: new Headers({ Authorization: 'Bearer token-1' }),
cache: 'no-store',
});
});

Expand All @@ -39,7 +40,10 @@ describe('default Edge Config', () => {
expect(fetchMock).toHaveBeenCalledTimes(1);
expect(fetchMock).toHaveBeenCalledWith(
`${baseUrl}/item/foo?version=1`,
{ headers: new Headers({ Authorization: 'Bearer token-1' }) },
{
headers: new Headers({ Authorization: 'Bearer token-1' }),
cache: 'no-store',
},
);
});
});
Expand Down Expand Up @@ -67,7 +71,10 @@ describe('default Edge Config', () => {
expect(fetchMock).toHaveBeenCalledTimes(1);
expect(fetchMock).toHaveBeenCalledWith(
`${baseUrl}/item/foo?version=1`,
{ headers: new Headers({ Authorization: 'Bearer token-1' }) },
{
headers: new Headers({ Authorization: 'Bearer token-1' }),
cache: 'no-store',
},
);
});
});
Expand All @@ -93,6 +100,7 @@ describe('default Edge Config', () => {
`${baseUrl}/item/foo?version=1`,
{
headers: new Headers({ Authorization: 'Bearer token-1' }),
cache: 'no-store',
},
);
});
Expand All @@ -111,6 +119,7 @@ describe('default Edge Config', () => {
`${baseUrl}/item/foo?version=1`,
{
headers: new Headers({ Authorization: 'Bearer token-1' }),
cache: 'no-store',
},
);
});
Expand All @@ -129,6 +138,7 @@ describe('default Edge Config', () => {
`${baseUrl}/item/foo?version=1`,
{
headers: new Headers({ Authorization: 'Bearer token-1' }),
cache: 'no-store',
},
);
});
Expand All @@ -145,6 +155,7 @@ describe('default Edge Config', () => {
expect(fetchMock).toHaveBeenCalledTimes(1);
expect(fetchMock).toHaveBeenCalledWith(`${baseUrl}/items?version=1`, {
headers: new Headers({ Authorization: 'Bearer token-1' }),
cache: 'no-store',
});
});
});
Expand All @@ -161,7 +172,10 @@ describe('default Edge Config', () => {
expect(fetchMock).toHaveBeenCalledTimes(1);
expect(fetchMock).toHaveBeenCalledWith(
`${baseUrl}/items?version=1&key=foo&key=bar`,
{ headers: new Headers({ Authorization: 'Bearer token-1' }) },
{
headers: new Headers({ Authorization: 'Bearer token-1' }),
cache: 'no-store',
},
);
});
});
Expand All @@ -185,7 +199,10 @@ describe('default Edge Config', () => {
expect(fetchMock).toHaveBeenCalledTimes(1);
expect(fetchMock).toHaveBeenCalledWith(
`${baseUrl}/items?version=1&key=foo&key=bar`,
{ headers: new Headers({ Authorization: 'Bearer token-1' }) },
{
headers: new Headers({ Authorization: 'Bearer token-1' }),
cache: 'no-store',
},
);
});
});
Expand All @@ -201,6 +218,7 @@ describe('default Edge Config', () => {
expect(fetchMock).toHaveBeenCalledTimes(1);
expect(fetchMock).toHaveBeenCalledWith(`${baseUrl}/items?version=1`, {
headers: new Headers({ Authorization: 'Bearer token-1' }),
cache: 'no-store',
});
});
});
Expand All @@ -216,6 +234,7 @@ describe('default Edge Config', () => {
expect(fetchMock).toHaveBeenCalledTimes(1);
expect(fetchMock).toHaveBeenCalledWith(`${baseUrl}/items?version=1`, {
headers: new Headers({ Authorization: 'Bearer token-1' }),
cache: 'no-store',
});
});
});
Expand All @@ -234,6 +253,7 @@ describe('default Edge Config', () => {
{
method: 'HEAD',
headers: new Headers({ Authorization: 'Bearer token-1' }),
cache: 'no-store',
},
);
});
Expand Down Expand Up @@ -265,6 +285,7 @@ describe('default Edge Config', () => {
{
method: 'HEAD',
headers: new Headers({ Authorization: 'Bearer token-1' }),
cache: 'no-store',
},
);
});
Expand Down Expand Up @@ -292,6 +313,7 @@ describe('default Edge Config', () => {
{
method: 'HEAD',
headers: new Headers({ Authorization: 'Bearer token-1' }),
cache: 'no-store',
},
);
});
Expand All @@ -308,6 +330,7 @@ describe('default Edge Config', () => {
expect(fetchMock).toHaveBeenCalledTimes(1);
expect(fetchMock).toHaveBeenCalledWith(`${baseUrl}/digest?version=1`, {
headers: new Headers({ Authorization: 'Bearer token-1' }),
cache: 'no-store',
});
});
});
Expand All @@ -323,6 +346,7 @@ describe('default Edge Config', () => {
expect(fetchMock).toHaveBeenCalledTimes(1);
expect(fetchMock).toHaveBeenCalledWith(`${baseUrl}/digest?version=1`, {
headers: new Headers({ Authorization: 'Bearer token-1' }),
cache: 'no-store',
});
});

Expand All @@ -336,6 +360,7 @@ describe('default Edge Config', () => {
expect(fetchMock).toHaveBeenCalledTimes(1);
expect(fetchMock).toHaveBeenCalledWith(`${baseUrl}/digest?version=1`, {
headers: new Headers({ Authorization: 'Bearer token-1' }),
cache: 'no-store',
});
});
});
Expand All @@ -351,6 +376,7 @@ describe('default Edge Config', () => {
expect(fetchMock).toHaveBeenCalledTimes(1);
expect(fetchMock).toHaveBeenCalledWith(`${baseUrl}/digest?version=1`, {
headers: new Headers({ Authorization: 'Bearer token-1' }),
cache: 'no-store',
});
});
});
Expand Down
8 changes: 7 additions & 1 deletion src/index.edge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export function createClient(
assertIsKey(key);
return fetchWithCachedResponse(`${url}/item/${key}?version=${version}`, {
headers: new Headers(headers),
cache: 'no-store',
}).then<T | undefined, undefined>(
(res) => {
if (res.status === 401) throw new Error(ERRORS.UNAUTHORIZED);
Expand All @@ -67,6 +68,7 @@ export function createClient(
return fetchWithCachedResponse(`${url}/item/${key}?version=${version}`, {
method: 'HEAD',
headers: new Headers(headers),
cache: 'no-store',
}).then(
(res) => {
if (res.status === 401) throw new Error(ERRORS.UNAUTHORIZED);
Expand Down Expand Up @@ -103,7 +105,10 @@ export function createClient(

return fetchWithCachedResponse(
`${url}/items?version=${version}${search === null ? '' : `&${search}`}`,
{ headers: new Headers(headers) },
{
headers: new Headers(headers),
cache: 'no-store',
},
).then<T>(
async (res) => {
if (res.status === 401) throw new Error(ERRORS.UNAUTHORIZED);
Expand All @@ -123,6 +128,7 @@ export function createClient(
async digest(): Promise<string> {
return fetchWithCachedResponse(`${url}/digest?version=1`, {
headers: new Headers(headers),
cache: 'no-store',
}).then(
(res) => {
if (res.cachedResponseBody !== undefined)
Expand Down
Loading

0 comments on commit becf6bf

Please sign in to comment.