@@ -2,11 +2,48 @@ part of 'services.dart';
22
33class ApiProvider {
44 factory ApiProvider () => _apiProvider;
5- ApiProvider ._() {
5+ ApiProvider ._();
6+ static final ApiProvider _apiProvider = ApiProvider ._();
7+
8+ Future <void > initialize () async {
69 final auth = UserRepository ().currentAppAuthentication;
710
11+ final documentsDir = await getApplicationDocumentsDirectory ();
12+
13+ // Global options
14+ final options = CacheOptions (
15+ // A default store is required for interceptor.
16+ store: SembastCacheStore (storePath: documentsDir.path),
17+
18+ // All subsequent fields are optional.
19+
20+ // Default.
21+ policy: CachePolicy .noCache,
22+ // Returns a cached response on error but for statuses 401 & 403.
23+ // Also allows to return a cached response on network errors (e.g. offline usage).
24+ // Defaults to [null].
25+ hitCacheOnErrorExcept: [401 , 403 ],
26+ // Overrides any HTTP directive to delete entry past this duration.
27+ // Useful only when origin server has no cache config or custom behaviour is desired.
28+ // Defaults to [null].
29+ maxStale: const Duration (days: 7 ),
30+ // Default. Allows 3 cache sets and ease cleanup.
31+ priority: CachePriority .normal,
32+ // Default. Body and headers encryption with your own algorithm.
33+ cipher: null ,
34+ // Default. Key builder to retrieve requests.
35+ keyBuilder: CacheOptions .defaultCacheKeyBuilder,
36+ // Default. Allows to cache POST requests.
37+ // Overriding [keyBuilder] is strongly recommended when [true].
38+ allowPostMethod: false ,
39+ );
40+
841 ncCookbookApi = NcCookbookApi (
942 basePathOverride: '${auth .server }/apps/cookbook' ,
43+ interceptors: [
44+ BasicAuthInterceptor (),
45+ DioCacheInterceptor (options: options),
46+ ],
1047 );
1148
1249 ncCookbookApi.setBasicAuth (
@@ -19,7 +56,6 @@ class ApiProvider {
1956 miscApi = ncCookbookApi.getMiscApi ();
2057 tagsApi = ncCookbookApi.getTagsApi ();
2158 }
22- static final ApiProvider _apiProvider = ApiProvider ._();
2359
2460 late NcCookbookApi ncCookbookApi;
2561 late RecipesApi recipeApi;
0 commit comments