Problem
We'd like to cache http-queries and define a lifetime for them.
Describe the solution you'd like
class Service extends GetConnect {
void onInit() {
httpClient.baseUrl = 'https://example.com/api';
httpClient.cache(Duration(days: 1));
await get('/endpoint');
// the body should be cached with the key https://example.com/api/endpoint and fetched if further request are sent within the duration
await get('/endpoint');
// get the cached version
// should be overridable with
await get('/endpoint', cache: false);
// get the fresh version
}
}
Describe alternatives you've considered
Override get(), post() ... etc methods by ourselfes.
It's a good idea, however I would recommend the cache to be disabled by default because it can get confusing if requests are being made but the returned data isn't up to date.
I think a implementation using GetStorage under the hood should be enough.
Maybe write extensions to GetStorage to suport cache to GetConnect can be a nice idea, I will try
Most helpful comment
Maybe write extensions to GetStorage to suport cache to GetConnect can be a nice idea, I will try