Skip to content

Commit

Permalink
[CacheInterceptor] Add ignore auto refresh functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
Vipin9821 authored and TusharFA committed Apr 1, 2024
1 parent be33b64 commit 9c7f5a7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
3 changes: 3 additions & 0 deletions lib/src/api_options/api_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class ApiOptions {
this.refreshCache,
this.expireDuration = const Duration(days: 1),
this.cancelToken,
this.ignoreAutoRefresh = false,
});

Map<String, dynamic>? headers;
Expand All @@ -21,4 +22,6 @@ class ApiOptions {
Duration? expireDuration;

CancelToken? cancelToken;

bool? ignoreAutoRefresh;
}
3 changes: 2 additions & 1 deletion lib/src/api_service_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@ class ApiServiceImpl implements ApiService {
"expirationTime": options?.expireDuration != null
? _now.add(options!.expireDuration!).toString()
: _midnightTime.toString(),
"expireDuration": options?.expireDuration
"expireDuration": options?.expireDuration,
"ignoreAutoRefresh": options?.ignoreAutoRefresh ?? false,
};
return headers;
}
Expand Down
3 changes: 3 additions & 0 deletions lib/src/interceptors/cache_interceptor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ abstract class ApiCacheInterceptor extends Interceptor {
),
);
if (!isValid) {
if (keyData['appSpecificHeaders']?['ignoreAutoRefresh'] ?? false) {
return null;
}
refreshCache(options);
}

Expand Down

0 comments on commit 9c7f5a7

Please sign in to comment.