ISwr.Use<T> method (1 of 3)
ISwr.Use<T> method (1 of 3)
Section titled “ISwr.Use<T> method (1 of 3)”Returns cached data immediately (if available) and revalidates in the background using the provided fetcher. The caller owns how data is retrieved — SWR only manages the cache.
public SwrResult<T> Use<T>(string? key, Func<string, Task<T?>> fetcher, SwrOptions? options = null, Action? onChange = null)| parameter | description |
|---|---|
| T | The type of data to fetch and cache. |
| key | The cache key identifying this data. |
| fetcher | A function that fetches fresh data given the cache key. |
| options | Per-request override of global SWR options, or null to use defaults. |
| onChange | Optional callback invoked when the result changes (initial fetch or revalidation). |
Return Value
Section titled “Return Value”A SwrResult that updates asynchronously as data flows through cache hit, fetch, and revalidation.
See Also
Section titled “See Also”- class SwrResult<T>
- record SwrOptions
- interface ISwr
- namespace Swr.Net
ISwr.Use<T,TArg> method (2 of 3)
Section titled “ISwr.Use<T,TArg> method (2 of 3)”Returns cached data for a composite key made of a URL and one additional argument. The tuple parts form the cache key (so different argument values yield separate cache entries) and are passed individually to the fetcher.
public SwrResult<T> Use<T, TArg>((string?, TArg) key, Func<string, TArg, Task<T?>> fetcher, SwrOptions? options = null, Action? onChange = null)| parameter | description |
|---|---|
| T | The type of data to fetch and cache. |
| TArg | The type of the additional key argument. |
| key | A tuple of (url, arg) that defines the composite cache key. |
| fetcher | A function that receives the URL and argument separately. |
| options | Per-request override of global SWR options, or null to use defaults. |
| onChange | Optional callback invoked when the result changes. |
Return Value
Section titled “Return Value”A SwrResult that updates asynchronously.
See Also
Section titled “See Also”- class SwrResult<T>
- record SwrOptions
- interface ISwr
- namespace Swr.Net
ISwr.Use<T,TArg1,TArg2> method (3 of 3)
Section titled “ISwr.Use<T,TArg1,TArg2> method (3 of 3)”Returns cached data for a composite key made of a URL and two additional arguments. The tuple parts form the cache key and are passed individually to the fetcher.
public SwrResult<T> Use<T, TArg1, TArg2>((string?, TArg1, TArg2) key, Func<string, TArg1, TArg2, Task<T?>> fetcher, SwrOptions? options = null, Action? onChange = null)| parameter | description |
|---|---|
| T | The type of data to fetch and cache. |
| TArg1 | The type of the first additional key argument. |
| TArg2 | The type of the second additional key argument. |
| key | A tuple of (url, arg1, arg2) that defines the composite cache key. |
| fetcher | A function that receives the URL and both arguments separately. |
| options | Per-request override of global SWR options, or null to use defaults. |
| onChange | Optional callback invoked when the result changes. |
Return Value
Section titled “Return Value”A SwrResult that updates asynchronously.
See Also
Section titled “See Also”- class SwrResult<T>
- record SwrOptions
- interface ISwr
- namespace Swr.Net