Add Query.withScheduledRefresh
Lint / lint (push) Successful in 1m53s

This commit is contained in:
Julien Valverdé
2026-07-30 13:09:24 +02:00
parent 4b712de788
commit e412943e64
4 changed files with 117 additions and 2 deletions
+27
View File
@@ -248,6 +248,33 @@ workflows that need to wait for the final success or failure state.
Invalidating does not itself refetch. Follow it with `refreshView`, change the
key, or allow a later fetch to repopulate the cache.
### Refresh on an interval
Refresh every five minutes, starting after five minutes:
```ts
import { Schedule } from "effect"
yield* query.pipe(
Query.withScheduledRefresh(Schedule.spaced("5 minutes")),
)
```
Limit the number of refreshes:
```ts
yield* query.pipe(
Query.withScheduledRefresh(
Schedule.spaced("5 minutes").pipe(
Schedule.upTo({ times: 3 }),
),
),
)
```
The refresh fiber stops with the surrounding scope. The Effect returns the
original query. Cache and `staleTime` rules still apply.
## Staleness and cache lifetime
`staleTime` controls how long a successful result can satisfy a fetch without