Getx: Define caching for GetConnect

Created on 9 Jan 2021  路  3Comments  路  Source: jonataslaw/getx

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.

Feature Request

Most helpful comment

Maybe write extensions to GetStorage to suport cache to GetConnect can be a nice idea, I will try

All 3 comments

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

omartinma picture omartinma  路  3Comments

DarkHeros09 picture DarkHeros09  路  3Comments

R-Praveen picture R-Praveen  路  4Comments

Nipodemos picture Nipodemos  路  4Comments

aytunch picture aytunch  路  4Comments