27 lines
722 B
Dart
27 lines
722 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: 100,
|
|
),
|
|
);
|
|
|
|
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!));
|
|
}
|
|
} |