Skip to content

Commit 7edb6cf

Browse files
committed
docs: add getCache function to README for retrieving cached data
1 parent 0672c4e commit 7edb6cf

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

README.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,26 @@ await mutate('/api/users', updatedData, {
306306
});
307307
```
308308

309+
##### `getCache(key)`
310+
311+
Directly retrieve cached data for a specific cache key. Useful for reading the current cached response without triggering a network request.
312+
313+
**Parameters:**
314+
315+
- `key` (string): The cache key to retrieve (equivalent to `cacheKey` from request config or `config.cacheKey` from response object)
316+
317+
**Returns:** The cached response object, or `undefined` if not found
318+
319+
```typescript
320+
import { getCache } from 'fetchff';
321+
322+
// Get cached data for a specific key assuming you set {cacheKey: ''/api/user-profile'} in config
323+
const cachedResponse = getCache('/api/user-profile');
324+
if (cachedResponse) {
325+
console.log('Cached user profile:', cachedResponse.data);
326+
}
327+
```
328+
309329
##### `setCache(key, response)`
310330

311331
Directly set cache data for a specific key. Unlike `mutate()`, this doesn't trigger revalidation by default. This is a low level function to directly set cache data based on particular key. If unsure, use the `mutate()` with `revalidate: false` instead.
@@ -1506,7 +1526,7 @@ The retry mechanism is configured via the `retry` option when instantiating the
15061526
If used in conjunction with `shouldRetry`, the `shouldRetry` function takes priority, and falls back to `retryOn` only if it returns `null`.
15071527
15081528
- **`shouldRetry(response: FetchResponse, currentAttempt: Number) => boolean`**:
1509-
Type: `RetryFunction<ResponseData, QueryParams, PathParams, RequestBody>`
1529+
Type: `RetryFunction<ResponseData, RequestBody, QueryParams, PathParams>`
15101530
Function that determines whether a retry should be attempted <b>based on the error</b> or <b>successful response</b> (if `shouldRetry` is provided) object, and the current attempt number. This function receives the error object and the attempt number as arguments. The boolean returned indicates decision. If `true` then it should retry, if `false` then abort and don't retry, if `null` then fallback to `retryOn` status codes check.
15111531
_Default:_ `undefined`.
15121532

0 commit comments

Comments
 (0)