cache manager: fix setLimitSize & checkCache

This commit is contained in:
Pacalini
2024-10-28 18:06:08 +08:00
parent 2025b5835b
commit 894f8cd162
2 changed files with 4 additions and 4 deletions

View File

@@ -135,7 +135,7 @@ class CacheManager {
WHERE expires < ? WHERE expires < ?
''', [DateTime.now().millisecondsSinceEpoch]); ''', [DateTime.now().millisecondsSinceEpoch]);
for(var row in res){ for(var row in res){
var dir = row[1] as int; var dir = row[1] as String;
var name = row[2] as String; var name = row[2] as String;
var file = File('$cachePath/$dir/$name'); var file = File('$cachePath/$dir/$name');
if(await file.exists()){ if(await file.exists()){
@@ -158,12 +158,12 @@ class CacheManager {
while((_currentSize != null && _currentSize! > _limitSize) || count > 2000){ while((_currentSize != null && _currentSize! > _limitSize) || count > 2000){
var res = _db.select(''' var res = _db.select('''
SELECT * FROM cache SELECT * FROM cache
ORDER BY time ASC ORDER BY expires ASC
limit 10 limit 10
'''); ''');
for(var row in res){ for(var row in res){
var key = row[0] as String; var key = row[0] as String;
var dir = row[1] as int; var dir = row[1] as String;
var name = row[2] as String; var name = row[2] as String;
var file = File('$cachePath/$dir/$name'); var file = File('$cachePath/$dir/$name');
if(await file.exists()){ if(await file.exists()){

View File

@@ -79,7 +79,7 @@ class _AppSettingsState extends State<AppSettings> {
appdata.saveData(); appdata.saveData();
setState(() {}); setState(() {});
CacheManager() CacheManager()
.setLimitSize(appdata.settings['cacheSize'] * 1024 * 1024); .setLimitSize(appdata.settings['cacheSize']);
return null; return null;
}, },
); );