Allows you to define custom logic to determine whether your local data is still valid or if it needs to be refreshed from the remote source using the Fetcher.
Validator has the following structure:
The type representing your domain data model. For example,
if you have a Store<Int, Post>
, the Output
is Post
.
A suspending function that determines whether the given item is still valid.
Data Retrieval Request
When your application requests cached data from the Store, it first checks the Memory Cache and the Source of Truth to see if the data is available.
The Validator only operates on data from the Source of Truth and does not validate data coming directly from the network.
Validation Check
The Validator’s isValid
method is called with the cached data as the parameter.
Data Update
If new data is fetched, it’s stored in the Memory Cache and the Source of Truth for future requests.
You can create a Validator using the Validator.by
factory method:
If your application has data that should be refreshed every 24 hours:
If your application data model changes and you need to invalidate old cached data:
In cases where authentication tokens expire:
isValid
function should execute quickly to avoid slowing down data retrieval. Complex computations or I/O operations should be avoided.Allows you to define custom logic to determine whether your local data is still valid or if it needs to be refreshed from the remote source using the Fetcher.
Validator has the following structure:
The type representing your domain data model. For example,
if you have a Store<Int, Post>
, the Output
is Post
.
A suspending function that determines whether the given item is still valid.
Data Retrieval Request
When your application requests cached data from the Store, it first checks the Memory Cache and the Source of Truth to see if the data is available.
The Validator only operates on data from the Source of Truth and does not validate data coming directly from the network.
Validation Check
The Validator’s isValid
method is called with the cached data as the parameter.
Data Update
If new data is fetched, it’s stored in the Memory Cache and the Source of Truth for future requests.
You can create a Validator using the Validator.by
factory method:
If your application has data that should be refreshed every 24 hours:
If your application data model changes and you need to invalidate old cached data:
In cases where authentication tokens expire:
isValid
function should execute quickly to avoid slowing down data retrieval. Complex computations or I/O operations should be avoided.