Methods
(async) get(options, updateStateopt) → {Promise.<(T|undefined)>}
Resolves a resource using the configured caching strategy.
| Name | Type | Attributes | Description |
|---|---|---|---|
options | CachedResourceOptions.<T> | Options defining the resource, key, and strategy. | |
updateState | function | <optional> | Optional callback to receive state updates (loading, success, error, revalidating). |
A promise that resolves to the data (if strategy allows immediate return) or undefined.
- Type:
- Promise.<(T|undefined)>
const data = await service.get({
key: 'user:1',
loader: () => fetch('/api/user/1').then(r => r.json()),
strategy: 'swr'
});(async) get(options, updateStateopt) → {Promise.<(T|undefined)>}
Resolves a resource using the configured caching strategy.
| Name | Type | Attributes | Description |
|---|---|---|---|
options | CachedResourceOptions.<T> | Options defining the resource, key, and strategy. | |
updateState | function | <optional> | Optional callback to receive state updates (loading, success, error, revalidating). |
A promise that resolves to the data (if strategy allows immediate return) or undefined.
- Type:
- Promise.<(T|undefined)>
const data = await service.get({
key: 'user:1',
loader: () => fetch('/api/user/1').then(r => r.json()),
strategy: 'swr'
});getDebugSnapshot()
Returns a debug snapshot of the current cache state.
getDebugSnapshot() → {CacheSnapshot}
Returns a debug snapshot of the current cache state.
- Type:
- CacheSnapshot
(async) invalidate(key) → {Promise.<void>}
Invalidates a cache entry by removing it from both memory and storage.
| Name | Type | Description |
|---|---|---|
key | CacheKey | The key to invalidate. |
- Type:
- Promise.<void>
(async) invalidate(key) → {Promise.<void>}
Invalidates a cache entry by removing it from both memory and storage.
| Name | Type | Description |
|---|---|---|
key | CacheKey | The key to invalidate. |
- Type:
- Promise.<void>
(async) set(key, data, ttlopt) → {Promise.<void>}
Manually sets a cache entry.
| Name | Type | Attributes | Description |
|---|---|---|---|
key | CacheKey | The key to set. | |
data | T | The data to store. | |
ttl | number | <optional> | Optional time-to-live in ms. |
- Type:
- Promise.<void>
(async) set(key, data, ttlopt) → {Promise.<void>}
Manually sets a cache entry.
| Name | Type | Attributes | Description |
|---|---|---|---|
key | CacheKey | The key to set. | |
data | T | The data to store. | |
ttl | number | <optional> | Optional time-to-live in ms. |
- Type:
- Promise.<void>