Open devmsh opened 2 years ago
I skipped these two policies:
Cache.get('api/v2/user_profile');
dioClient.get('api/v2/user_profile');
and I and I added one optional policy for the (get post, put and delete) requests:
cache request on network connection failed: the API client will cache the request and try to perform it again after connecting to the network again
This is just a pseudo code
enum CachePolicy {
cacheElseNetwork,
cacheThenNetwork,
networkElseCache,
networkOnly
}
class CachableApiClient {
final HttpClient _client;
final CacheDriver _cache;
CachableApiClient(this._client, this._cache);
Stream<T> get<T>(
String path, {
Map<String, dynamic>? queryParameters,
Options? options,
CachePolicy? policy = null,
bool smartRequestPolicyOnConnectivityFailed = false,
});
Stream<T> post<T>(
String path, {
Map<String, dynamic>? queryParameters,
Options? options,
bool smartRequestPolicyOnConnectivityFailed = false,
});
Stream<T> put<T>(
String path, {
Map<String, dynamic>? queryParameters,
Options? options,
bool smartRequestPolicyOnConnectivityFailed = false,
}) ;
Future<T> delete<T>(
String path, {
Map<String, dynamic>? queryParameters,
Options? options,
bool smartRequestPolicyOnConnectivityFailed = false,
});
}
most of the methods return stream due to the fact it emits more than one result from multi-data sources (cache and remote) and on else cache policy we can emit an error with the stream to tell the client about the failure of fetch operation from the first data source, then emit the results from the fallback data source.
smartRequestPolicyOnConnectivityFailed, will try to perform the request again directly when the device back to online mode.
WIP
https://parseplatform.org/Parse-SDK-Android/api/com/parse/ParseQuery.CachePolicy.html