ToneSnap_FSX_Flutter/lib/data/cache/music_cache_manager.dart
fengshengxiong da21720c3c 1.首页增加下拉刷新
2.修改下载状态监听方式,实现全局同步
3.修复搜索无结果时页面报错
4.歌单页面点击播放全部和随机是播放当前歌单列表
2024-08-06 15:52:07 +08:00

27 lines
721 B
Dart

// Author: fengshengxiong
// Date: 2024/6/25
// Description: 自定义音乐缓存管理器
import 'package:flutter_cache_manager/flutter_cache_manager.dart';
import 'package:tone_snap/utils/obj_util.dart';
class MusicCacheManager {
static const key = 'musicCacheKey';
static CacheManager instance = CacheManager(
Config(
key,
stalePeriod: const Duration(days: 7),
maxNrOfCacheObjects: 30,
),
);
static String getCacheKey(String videoId) {
return 'music_$videoId';
}
/// 检查是否有缓存
static Future<FileInfo?> checkCache(String? videoId) async {
if (ObjUtil.isEmpty(videoId)) return null;
return await instance.getFileFromCache(getCacheKey(videoId!));
}
}