dio_http_cache 0.1.0 dio_http_cache: ^0.1.0 copied to clipboard
http cache lib for Flutter dio like RxCache.It use sqflite as disk cache,and google/quiver-dart/LRU strategy as memory cache.
dio-http-cache #
Dio-http-cache is a cache library for Dio ( http client for flutter ), like Rxcache in Android.
Dio-http-cache uses sqflite as disk cache, and LRU strategy as memory cache.
Inspired by flutter_cache_manager.
Add Dependency #
dio_http_cache ^0.1.0
QuickStart #
-
Add a dio-http-cache interceptor in Dio :
dio.interceptors.add(DioCacheManager(CacheConfig()).interceptor);
-
Set maxAge for a request :
Dio().get( "http://www.google.com", options: buildCacheOptions(Duration(days: 7)), );
The advanced #
-
MaxAge: return cache directly before maxAge.
-
MaxStale: when errors occur, try to return cache before maxSotale.
buildCacheOptions(Duration(days: 7), maxStale: Duration(days: 10))
-
encrypt / decrypt: custom encrypt config with
CacheConfig
. -
subKey: dio-http-cache use url as key, you can add a subKey when necessary, such as different params with the same request.
License #
Copyright 2019 Hurshi
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.