Skip to content
This repository was archived by the owner on Nov 2, 2023. It is now read-only.

Commit dfe4a1d

Browse files
committed
feat: Rename clearCache to refresh
BREAKING CHANGE: clearCache is now called refresh
1 parent b198be0 commit dfe4a1d

File tree

11 files changed

+25
-25
lines changed

11 files changed

+25
-25
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ can be used to rerender outdated components
171171

172172
```ts
173173
const userLoader = createGetEndpoint(...)
174-
userLoader.clearCache()
174+
userLoader.refresh()
175175
```
176176

177177
## Disabling Cache
@@ -209,7 +209,7 @@ const getUserName = createGetEndpoint({
209209
})
210210
const setUserName = createPostEndpoint({
211211
url: keys => `http://example.com/user/${keys.id}/update`,
212-
afterSuccess: () => getUserName.clearCache();
212+
afterSuccess: () => getUserName.refresh();
213213
})
214214
```
215215

@@ -290,7 +290,7 @@ const userEndpoint = createGetEndpoint<Input, Output>({
290290

291291
## Endpoint observing
292292

293-
Invalidating the cache using `clearCache` will internaly trigger a clearCache event.
293+
Invalidating the cache using `refresh` will internaly trigger a refresh event.
294294
To subscribe to the initial data load and updates after a clear cache it is possible to observe an endpoint:
295295

296296
```js

core/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ can be used to rerender outdated components
171171

172172
```ts
173173
const userLoader = createGetEndpoint(...)
174-
userLoader.clearCache()
174+
userLoader.refresh()
175175
```
176176

177177
## Disabling Cache
@@ -209,7 +209,7 @@ const getUserName = createGetEndpoint({
209209
})
210210
const setUserName = createPostEndpoint({
211211
url: keys => `http://example.com/user/${keys.id}/update`,
212-
afterSuccess: () => getUserName.clearCache();
212+
afterSuccess: () => getUserName.refresh();
213213
})
214214
```
215215

@@ -290,7 +290,7 @@ const userEndpoint = createGetEndpoint<Input, Output>({
290290

291291
## Endpoint observing
292292

293-
Invalidating the cache using `clearCache` will internaly trigger a clearCache event.
293+
Invalidating the cache using `refresh` will internaly trigger a refresh event.
294294
To subscribe to the initial data load and updates after a clear cache it is possible to observe an endpoint:
295295

296296
```js

core/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export interface EndpointGetFunction<TKeys extends {}, TResult extends unknown>
7474
/**
7575
* Clear the cache for this url
7676
*/
77-
clearCache: () => void;
77+
refresh: () => void;
7878
/**
7979
* Cache Key
8080
*/

core/src/lib/CacheStore.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ export interface CacheStore<TKeys, TResult> {
1717
/**
1818
* Clear the cache for this url
1919
*/
20-
clearCache: () => void;
20+
refresh: () => void;
2121
/**
2222
* Cache Key
2323
*/
2424
getCacheKey: (keys: TKeys) => string;
2525
/**
2626
* The time of the first write into the cache
27-
* will be reset on clearCache
27+
* will be reset on refresh
2828
*/
2929
_state: { _cacheCreation?: Date };
3030
/**
@@ -135,14 +135,14 @@ export function createCacheStore<
135135
callback: (result: Promise<TResult>) => any,
136136
timeout?: number
137137
) => () => void;
138-
clearCache: () => Promise<any[]>;
138+
refresh: () => Promise<any[]>;
139139
} = {
140140
cache,
141141
_state: cacheState,
142142
getCacheKey: cacheKeyGenerator
143143
? keys => cacheKeyGenerator(keys, getUrlCacheKey(keys))
144144
: getUrlCacheKey,
145-
clearCache: () => {
145+
refresh: () => {
146146
const previousCacheCreation = cacheState._cacheCreation;
147147
let cacheClearHandlers: Array<Promise<any> | void> = [];
148148
if (previousCacheCreation) {

core/test/index.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ test("should allow to use observePromise to obtain the endpoints value", async (
205205
// Get first value
206206
expect(await latestPromise).toEqual({ run: 0 });
207207
// Clear cache
208-
runCountEndpoint.clearCache();
208+
runCountEndpoint.refresh();
209209
jest.runAllTimers();
210210
// Verify that the value is not comming from cache
211211
expect(await latestPromise).toEqual({ run: 1 });
@@ -236,7 +236,7 @@ test("should allow to use observe to obtain the endpoints value", async () => {
236236
expect(latestValue).toEqual({ run: 0 });
237237
nextChangePromise = createDeferred();
238238
// Clear cache
239-
runCountEndpoint.clearCache();
239+
runCountEndpoint.refresh();
240240
jest.runAllTimers();
241241
// Verify that the value is not comming from cache
242242
await nextChangePromise;

utils/request-registry-mobx/test/index.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ describe('request-registry-mobx', () => {
191191
await when(() => endpoint.state === 'DONE');
192192
expect(endpoint.value).toEqual({ runs: 1 });
193193
// Invalidate the cache:
194-
runEndpoint.clearCache();
194+
runEndpoint.refresh();
195195
// Wait for a new run count
196196
await when(() =>
197197
Boolean(endpoint.value && endpoint.value.runs !== 1)
@@ -212,7 +212,7 @@ describe('request-registry-mobx', () => {
212212
// Start observing the endpoint:
213213
const unobserve = autorun(() => endpoint.value);
214214
// Invalidate the cache:
215-
runEndpoint.clearCache();
215+
runEndpoint.refresh();
216216
expect(endpoint.busy).toEqual(true);
217217
unobserve();
218218
});

utils/request-registry-mock/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ The `mockEndpointOnce` is similar to `mockEndpoint` however it will unbind after
7070
const userEndpoint = createGetEndpoint({ url: () => '/user' });
7171
mockEndpointOnce(getUserName, async () => ({ name: 'Joe' }));
7272
console.log(await userEndpoint()); // Will return the mocked value `{name: 'Joe'}`
73-
userEndpoint.clearCache();
73+
userEndpoint.refresh();
7474
console.log(await userEndpoint()); // Will return the value of an unmocked call`
7575
```
7676

utils/request-registry-mock/test/index.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ describe('request-registry-mock', () => {
130130
userEndpointMock1.activate();
131131
userEndpointMock2.activate();
132132
expect(await userEndpoint({})).toEqual({ name: 'Chris' });
133-
userEndpoint.clearCache();
133+
userEndpoint.refresh();
134134
userEndpointMock2.clear();
135135
expect(await userEndpoint({})).toEqual({ name: 'Alex' });
136136
});
@@ -155,7 +155,7 @@ describe('request-registry-mock', () => {
155155
userEndpointMock1.activate();
156156
userEndpointMock2.activate();
157157
expect(await userEndpoint({})).toEqual({ name: 'Chris' });
158-
userEndpoint.clearCache();
158+
userEndpoint.refresh();
159159
userEndpointMock1.clear();
160160
expect(await userEndpoint({})).toEqual({ name: 'Chris' });
161161
userEndpointMock2.clear();
@@ -171,7 +171,7 @@ describe('request-registry-mock', () => {
171171
mockEndpointOnce(userEndpoint, async () => ({ name: 'Alex' }));
172172
mockEndpointOnce(userEndpoint, async () => ({ name: 'Chris' }));
173173
expect(await userEndpoint({})).toEqual({ name: 'Chris' });
174-
userEndpoint.clearCache();
174+
userEndpoint.refresh();
175175
expect(await userEndpoint({})).toEqual({ name: 'Alex' });
176176
});
177177
});
@@ -196,7 +196,7 @@ describe('request-registry-mock', () => {
196196
activateMocks(userEndpointMock1, userEndpointMock2);
197197
expect(await userEndpoint({})).toEqual({ name: 'Chris' });
198198
userEndpointMock2.clear();
199-
userEndpoint.clearCache();
199+
userEndpoint.refresh();
200200
expect(await userEndpoint({})).toEqual({ name: 'Alex' });
201201
});
202202
});

utils/request-registry-react/example/endpoints.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ export const loginEndpoint = createPostEndpoint<
2121
{}
2222
>({
2323
url: () => `/user/login`,
24-
afterSuccess: () => productsEndpoint.clearCache()
24+
afterSuccess: () => productsEndpoint.refresh()
2525
});
2626

2727
export const logoutEndpoint = createPostEndpoint<{}, {}, {}>({
2828
url: () => `/user/logout`,
29-
afterSuccess: () => productsEndpoint.clearCache()
29+
afterSuccess: () => productsEndpoint.refresh()
3030
});

utils/request-registry-react/test/index.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ describe("request-registry-react", () => {
7474
const { container } = render(<Runs />);
7575
await wait();
7676
expect(container.innerHTML).toEqual("<div>0</div>");
77-
runsEndpoint.clearCache();
77+
runsEndpoint.refresh();
7878
await wait();
7979
expect(container.innerHTML).toEqual("<div>1</div>");
8080
});
@@ -108,7 +108,7 @@ describe("request-registry-react", () => {
108108
async () => ({ name: "Fast", age: 1 }),
109109
1
110110
);
111-
userEndpoint.clearCache();
111+
userEndpoint.refresh();
112112
// Execute fast request
113113
await userEndpoint({ id: "4" });
114114
await slowRequest;

0 commit comments

Comments
 (0)