Add a dio-http-cache interceptor in Dio : dio.interceptors.add(DioCacheManager(CacheConfig(baseUrl: "http://www.google.com")).interceptor); Set maxAge for a request : Dio().get( "http://www.google.com", options: buildCacheOptions(Duration(days: 7)), );...
Dio-http-cache 是 Flutter 的 http 缓存库,为 Dio 设计,就像 Android 中的 RxCache 一样; Dio-http-cache 使用 sqflite 作为磁盘缓存,使用 Google/quiver-dart 的LRU算法 作为内存缓存策略; 有参考 flutter_cache_manager 开发,为此感谢. 添加依赖 dio_http_cache: ^0.1.0 简单使用 为dio 添加拦截器: dio...
CacheControl CacheControl类用于表示 HTTP 请求和响应中的Cache-Control头部的子集信息。Cache-Control是一个用于指定缓存策略的 HTTP 头部字段,它可以包含多个指令,如max-age、no-cache、no-store等,用于控制缓存的行为。 这里的CacheControl类可能是为了从缓存响应中解析出Cache-Control头部的信息,或者用于构建新的Cache...
if (cacheResponse != null) {/// 命中缓存, 更新缓存的时间, 并将缓存返回// Cache hit// Update cached response if neededcacheResponse = await_updateCacheResponse(cacheResponse, cacheOptions);/// 将缓存的结果response返回handler.resolve( cacheResponse.toResponse(options, fromNetwork: false), true,...
dio_http_cache A cache library for Dio, like Rxcache in Android. dio-http-cache uses sqflite as disk cache, and LRU strategy as memory cache. retrofit retrofit.dart is an dio client generator using source_gen and inspired by Chopper and Retrofit. dio_firebase_performance A Dio Interceptor fo...
BASE_URL = "http://39.108.223.110:9199"; /// 是否开启网络缓存,默认false static bool CACHE_ENABLE = false; /// 最大缓存时间(按秒), 默认缓存七天,可自行调节 static int MAX_CACHE_AGE = 7 * 24 * 60 * 60; /// 最大缓存条数(默认一百条) static int MAX_CACHE_COUNT = 100; static ...
^0.2.x # latest version 快速开始 在Dio中添加一个dio-http-cache拦截器: dio.interceptors. add ( DioCacheManager ( CacheConfig (baseUrl : "http://www.google.com" )).interceptor); 为请求设置maxAge: Dio (). get ( "http://www.google.com" , options : buildCacheOptions ( Duration (days...
final _cache = <Uri, Response>{}; @override void onRequest(RequestOptions options, RequestInterceptorHandler handler) { final response = _cache[options.uri]; if (response != null) { // 如果缓存中存在响应,则直接返回缓存的响应 handler.resolve(response); ...
Dio是一个强大的Dart HTTP客户端,支持拦截器、全局配置、FormData、请求取消、文件下载、超时等。它的特性包括但不限于: 全局配置,如基础URL、连接超时时间、接收超时时间等,简化了请求的配置。 FormData,方便地处理表单数据和文件上传。 请求取消,提供了取消正在进行的HTTP请求的能力。
缓存接口:可以对于某些接口将请求缓存在本地,设定一定的缓存有效时限,在时限内重复请求时直接返回本地缓存数据,而无需请求后端接口,降低后端服务器负荷。这块可以参考dio-http-cache。 Cookie:App 本身是不会缓存 Cookie 信息的,可以使用拦截器在向后端发起请求时自动携带 Cookie信息,可以参考cookie_manager。