提交 67c93b6c authored 作者: yueweilu's avatar yueweilu

没有数据时 获取缓存key 不一致问题

上级 9c507981
......@@ -343,10 +343,10 @@ class _CacheInterceptor extends Interceptor {
final status = await Tools.checkCurrentNetStatus();
if (cacheEnabled && !status) {
// 在发起请求之前,检查缓存是否存在有效数据
String cacheKey = options.data.isEmpty ? options.uri.toString() : '${options.uri.toString()}?${options.data}';
String cacheKey = '${options.uri.toString()}?${options.data}';
final cachedFile = await DefaultCacheManager().getFileFromCache(cacheKey);
Console.log('获取数据----------cacheKey-----------------------$cacheKey');
if (cachedFile != null && cachedFile.validTill.isAfter(DateTime.now())) {
Console.log('-获取数据cachedFile------------------------------$cachedFile-');
// 如果缓存有效,直接返回缓存数据
final cachedData = await cachedFile.file.readAsBytes();
final decodedData = utf8.decode(cachedData); // 将字节列表解码为字符串
......@@ -383,7 +383,7 @@ class _CacheInterceptor extends Interceptor {
cacheKey,
uint8List,
fileExtension: '.json', // 可以根据需求修改文件扩展名
maxAge: const Duration(hours: 1)
maxAge: const Duration(hours: 12)
);
} catch (e) {
Console.log('Error caching response: $e');
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论