mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-07-17 14:50:12 +08:00
opt: cache clean
This commit is contained in:
@@ -110,8 +110,6 @@ void main() async {
|
|||||||
..lazyPut(DownloadService.new);
|
..lazyPut(DownloadService.new);
|
||||||
HttpOverrides.global = _CustomHttpOverrides();
|
HttpOverrides.global = _CustomHttpOverrides();
|
||||||
|
|
||||||
CacheManager.autoClearCache();
|
|
||||||
|
|
||||||
if (PlatformUtils.isMobile) {
|
if (PlatformUtils.isMobile) {
|
||||||
if (Platform.isAndroid) MaxScreenSize.init();
|
if (Platform.isAndroid) MaxScreenSize.init();
|
||||||
await Future.wait([
|
await Future.wait([
|
||||||
|
|||||||
@@ -595,19 +595,10 @@ List<SettingsModel> get extraSettings => [
|
|||||||
onTap: _showProxyDialog,
|
onTap: _showProxyDialog,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SwitchModel(
|
|
||||||
title: '自动清除缓存',
|
|
||||||
subtitle: '每次启动时清除缓存',
|
|
||||||
leading: Icon(Icons.auto_delete_outlined),
|
|
||||||
setKey: SettingBoxKey.autoClearCache,
|
|
||||||
defaultVal: false,
|
|
||||||
),
|
|
||||||
NormalModel(
|
NormalModel(
|
||||||
title: '最大缓存大小',
|
title: '最大缓存大小',
|
||||||
getSubtitle: () {
|
getSubtitle: () =>
|
||||||
final num = Pref.maxCacheSize;
|
'当前最大缓存大小: 「${CacheManager.formatSize(Pref.maxCacheSize)}」',
|
||||||
return '当前最大缓存大小: 「${num == 0 ? '无限' : CacheManager.formatSize(Pref.maxCacheSize)}」';
|
|
||||||
},
|
|
||||||
leading: const Icon(Icons.delete_outlined),
|
leading: const Icon(Icons.delete_outlined),
|
||||||
onTap: _showCacheDialog,
|
onTap: _showCacheDialog,
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import 'dart:io' show Directory, File;
|
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/platform_utils.dart';
|
||||||
import 'package:PiliPlus/utils/storage_pref.dart';
|
import 'package:PiliPlus/utils/storage_pref.dart';
|
||||||
import 'package:cached_network_image_ce/cached_network_image.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 {
|
abstract final class CacheManager {
|
||||||
static late final DefaultCacheManager manager;
|
static late final DefaultCacheManager manager;
|
||||||
|
|
||||||
static Future<void> ensureInitialized() =>
|
static Future<void> ensureInitialized() => DefaultCacheManager.init(
|
||||||
DefaultCacheManager.init().then((i) => manager = i);
|
maxNrOfCacheLength: Pref.maxCacheSize.toInt(),
|
||||||
|
).then((i) => manager = i);
|
||||||
|
|
||||||
// 获取缓存目录
|
// 获取缓存目录
|
||||||
@pragma('vm:notify-debugger-on-exception')
|
@pragma('vm:notify-debugger-on-exception')
|
||||||
static Future<int> loadApplicationCache() async {
|
static Future<int> loadApplicationCache() async {
|
||||||
try {
|
try {
|
||||||
final Directory tempDirectory = await getTemporaryDirectory();
|
|
||||||
if (PlatformUtils.isDesktop) {
|
if (PlatformUtils.isDesktop) {
|
||||||
return manager.getTotalLength();
|
return manager.getTotalLength();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Directory tempDirectory = await getTemporaryDirectory();
|
||||||
if (tempDirectory.existsSync()) {
|
if (tempDirectory.existsSync()) {
|
||||||
return await getTotalSizeOfFilesInDir(tempDirectory);
|
return await getTotalSizeOfFilesInDir(tempDirectory);
|
||||||
}
|
}
|
||||||
@@ -81,22 +81,4 @@ abstract final class CacheManager {
|
|||||||
}
|
}
|
||||||
} catch (_) {}
|
} 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',
|
banWordForRecommend = 'banWordForRecommend',
|
||||||
applyFilterToRelatedVideos = 'applyFilterToRelatedVideos',
|
applyFilterToRelatedVideos = 'applyFilterToRelatedVideos',
|
||||||
autoUpdate = 'autoUpdate',
|
autoUpdate = 'autoUpdate',
|
||||||
autoClearCache = 'autoClearCache',
|
|
||||||
maxCacheSize = 'maxCacheSize',
|
maxCacheSize = 'maxCacheSize',
|
||||||
defaultShowComment = 'defaultShowComment',
|
defaultShowComment = 'defaultShowComment',
|
||||||
replySortType = 'replySortType',
|
replySortType = 'replySortType',
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
import 'dart:math' show pow;
|
|
||||||
|
|
||||||
import 'package:PiliPlus/common/widgets/gesture/horizontal_drag_gesture_recognizer.dart'
|
import 'package:PiliPlus/common/widgets/gesture/horizontal_drag_gesture_recognizer.dart'
|
||||||
show deviceTouchSlop;
|
show deviceTouchSlop;
|
||||||
@@ -598,7 +597,7 @@ abstract final class Pref {
|
|||||||
_setting.get(SettingBoxKey.showPgcTimeline, defaultValue: true);
|
_setting.get(SettingBoxKey.showPgcTimeline, defaultValue: true);
|
||||||
|
|
||||||
static num get maxCacheSize =>
|
static num get maxCacheSize =>
|
||||||
_setting.get(SettingBoxKey.maxCacheSize) ?? pow(1024, 3);
|
_setting.get(SettingBoxKey.maxCacheSize) ?? 1 << 30;
|
||||||
|
|
||||||
static bool get optTabletNav =>
|
static bool get optTabletNav =>
|
||||||
_setting.get(SettingBoxKey.optTabletNav, defaultValue: true);
|
_setting.get(SettingBoxKey.optTabletNav, defaultValue: true);
|
||||||
@@ -717,9 +716,6 @@ abstract final class Pref {
|
|||||||
!Platform.isIOS &&
|
!Platform.isIOS &&
|
||||||
_setting.get(SettingBoxKey.dynamicColor, defaultValue: true);
|
_setting.get(SettingBoxKey.dynamicColor, defaultValue: true);
|
||||||
|
|
||||||
static bool get autoClearCache =>
|
|
||||||
_setting.get(SettingBoxKey.autoClearCache, defaultValue: false);
|
|
||||||
|
|
||||||
static bool get enableSystemProxy =>
|
static bool get enableSystemProxy =>
|
||||||
_setting.get(SettingBoxKey.enableSystemProxy, defaultValue: false);
|
_setting.get(SettingBoxKey.enableSystemProxy, defaultValue: false);
|
||||||
|
|
||||||
|
|||||||
10
pubspec.lock
10
pubspec.lock
@@ -207,17 +207,17 @@ packages:
|
|||||||
description:
|
description:
|
||||||
path: cached_network_image
|
path: cached_network_image
|
||||||
ref: develop
|
ref: develop
|
||||||
resolved-ref: "5b79ff9f53a9a55b57d4d6fc52eb529fdfdb30d7"
|
resolved-ref: "6ad91e9bf71254803e222b7d254751576f2f6d7b"
|
||||||
url: "https://github.com/bggRGjQaUbCoE/flutter_cached_network_image_ce.git"
|
url: "https://github.com/My-Responsitories/flutter_cached_network_image_ce.git"
|
||||||
source: git
|
source: git
|
||||||
version: "4.6.4"
|
version: "4.6.4"
|
||||||
cached_network_image_platform_interface_ce:
|
cached_network_image_platform_interface_ce:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
path: cached_network_image_platform_interface
|
path: cached_network_image_platform_interface
|
||||||
ref: "5b79ff9f53a9a55b57d4d6fc52eb529fdfdb30d7"
|
ref: "6ad91e9bf71254803e222b7d254751576f2f6d7b"
|
||||||
resolved-ref: "5b79ff9f53a9a55b57d4d6fc52eb529fdfdb30d7"
|
resolved-ref: "6ad91e9bf71254803e222b7d254751576f2f6d7b"
|
||||||
url: "https://github.com/bggRGjQaUbCoE/flutter_cached_network_image_ce.git"
|
url: "https://github.com/My-Responsitories/flutter_cached_network_image_ce.git"
|
||||||
source: git
|
source: git
|
||||||
version: "5.2.0"
|
version: "5.2.0"
|
||||||
canvas_danmaku:
|
canvas_danmaku:
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ dependencies:
|
|||||||
brotli: ^0.6.0
|
brotli: ^0.6.0
|
||||||
cached_network_image_ce:
|
cached_network_image_ce:
|
||||||
git:
|
git:
|
||||||
url: https://github.com/bggRGjQaUbCoE/flutter_cached_network_image_ce.git
|
url: https://github.com/My-Responsitories/flutter_cached_network_image_ce.git
|
||||||
path: cached_network_image
|
path: cached_network_image
|
||||||
ref: develop
|
ref: develop
|
||||||
canvas_danmaku:
|
canvas_danmaku:
|
||||||
@@ -224,6 +224,11 @@ dependency_overrides:
|
|||||||
url: https://github.com/bggRGjQaUbCoE/screen_brightness.git
|
url: https://github.com/bggRGjQaUbCoE/screen_brightness.git
|
||||||
path: screen_brightness_android
|
path: screen_brightness_android
|
||||||
ref: main
|
ref: main
|
||||||
|
cached_network_image_ce:
|
||||||
|
git:
|
||||||
|
url: https://github.com/My-Responsitories/flutter_cached_network_image_ce.git
|
||||||
|
path: cached_network_image
|
||||||
|
ref: develop
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
|
|||||||
Reference in New Issue
Block a user