mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-06-29 13:50:21 +08:00
opt: cache clean
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import 'dart:io' show Directory, File;
|
||||
|
||||
import 'package:PiliPlus/utils/extension/file_ext.dart';
|
||||
import 'package:PiliPlus/utils/platform_utils.dart';
|
||||
import 'package:PiliPlus/utils/storage_pref.dart';
|
||||
import 'package:cached_network_image_ce/cached_network_image.dart';
|
||||
@@ -10,18 +9,19 @@ import 'package:path_provider/path_provider.dart';
|
||||
abstract final class CacheManager {
|
||||
static late final DefaultCacheManager manager;
|
||||
|
||||
static Future<void> ensureInitialized() =>
|
||||
DefaultCacheManager.init().then((i) => manager = i);
|
||||
static Future<void> ensureInitialized() => DefaultCacheManager.init(
|
||||
maxNrOfCacheLength: Pref.maxCacheSize.toInt(),
|
||||
).then((i) => manager = i);
|
||||
|
||||
// 获取缓存目录
|
||||
@pragma('vm:notify-debugger-on-exception')
|
||||
static Future<int> loadApplicationCache() async {
|
||||
try {
|
||||
final Directory tempDirectory = await getTemporaryDirectory();
|
||||
if (PlatformUtils.isDesktop) {
|
||||
return manager.getTotalLength();
|
||||
}
|
||||
|
||||
final Directory tempDirectory = await getTemporaryDirectory();
|
||||
if (tempDirectory.existsSync()) {
|
||||
return await getTotalSizeOfFilesInDir(tempDirectory);
|
||||
}
|
||||
@@ -81,22 +81,4 @@ abstract final class CacheManager {
|
||||
}
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
static Future<void> autoClearCache() async {
|
||||
// TODO: remove
|
||||
Directory(
|
||||
'${(await getTemporaryDirectory()).path}/libCachedImageData',
|
||||
).tryDel(recursive: true);
|
||||
if (Pref.autoClearCache) {
|
||||
await clearLibraryCache();
|
||||
} else {
|
||||
final maxCacheSize = Pref.maxCacheSize;
|
||||
if (maxCacheSize != 0) {
|
||||
final currCache = await loadApplicationCache();
|
||||
if (currCache >= maxCacheSize) {
|
||||
await clearLibraryCache();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,7 +56,6 @@ abstract final class SettingBoxKey {
|
||||
banWordForRecommend = 'banWordForRecommend',
|
||||
applyFilterToRelatedVideos = 'applyFilterToRelatedVideos',
|
||||
autoUpdate = 'autoUpdate',
|
||||
autoClearCache = 'autoClearCache',
|
||||
maxCacheSize = 'maxCacheSize',
|
||||
defaultShowComment = 'defaultShowComment',
|
||||
replySortType = 'replySortType',
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import 'dart:io';
|
||||
import 'dart:math' show pow;
|
||||
|
||||
import 'package:PiliPlus/common/widgets/gesture/horizontal_drag_gesture_recognizer.dart'
|
||||
show deviceTouchSlop;
|
||||
@@ -598,7 +597,7 @@ abstract final class Pref {
|
||||
_setting.get(SettingBoxKey.showPgcTimeline, defaultValue: true);
|
||||
|
||||
static num get maxCacheSize =>
|
||||
_setting.get(SettingBoxKey.maxCacheSize) ?? pow(1024, 3);
|
||||
_setting.get(SettingBoxKey.maxCacheSize) ?? 1 << 30;
|
||||
|
||||
static bool get optTabletNav =>
|
||||
_setting.get(SettingBoxKey.optTabletNav, defaultValue: true);
|
||||
@@ -717,9 +716,6 @@ abstract final class Pref {
|
||||
!Platform.isIOS &&
|
||||
_setting.get(SettingBoxKey.dynamicColor, defaultValue: true);
|
||||
|
||||
static bool get autoClearCache =>
|
||||
_setting.get(SettingBoxKey.autoClearCache, defaultValue: false);
|
||||
|
||||
static bool get enableSystemProxy =>
|
||||
_setting.get(SettingBoxKey.enableSystemProxy, defaultValue: false);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user