Query:
= Request for information.
Cached Query:
1. Saving the results of a data request (query) so you can use them again later without
needing to fetch the data every time.
2. Cached_query relies on timestamp-based expiry.
QueryConfigFlutter(storeQuery: true, staleTime: Duration(minutes: 5)):
Now, after 5 minutes, the cache is considered "stale" and will refetch the next
time QueryBuilder is rebuilt.
For refetch-on-mount (when widget is rebuilt/shown):
QueryConfigFlutter(storeQuery: true, refetchOnMount: true)
Action What happens
Data fetched Cache saves data & timestamp
Widget remounts Checks cache age (timestamp)
Age < staleTime Uses cache (no API call)
Age > staleTime Refetches from API
Action Mount? Rebuild?
First time screen opens ✅ ✅
Call setState() in widget ❌ ✅
Navigate away and back (pop/push) ✅ ✅
Hot reload ❌ ✅
staleTime: Sets the cache’s freshness period.
refetchOnMount: Auto-refetches cache on widget mount if stale.
What? .fetch() QueryBuilder
Type Function Widget
Used in Controllers, logic UI (widgets)
UI updates Manual Automatic
How to
await fetch() QueryBuilder(...)
use
Method Checks staleTime? Checks refetchOnMount? Always fetches?
.fetch() ❌ ❌ ✅
QueryBuilder ✅ ✅ ❌
you’ll use .fetch() with GetX for offline cache if you set up caching (manually or with
a library).
Otherwise, it’s just a regular API call.
Cached Storage:
key value createdAt expiresAt stale
{"data": {"id": 5,
"name": "John"},
"createdAt": "2025-09- 2025-09- 2025-09-
getAttendance?
19T16:41:53Z", 19 19 false
userId=5
"expiresAt": "2025-09- 16:41:53 17:41:53
19T17:41:53Z", "stale":
false}