old cache gets deleted

This commit is contained in:
2024-04-01 14:18:23 +02:00
parent 75846750f7
commit 6c2c305f1c
3 changed files with 20 additions and 2 deletions

View File

@ -0,0 +1,15 @@
import 'package:localstore/localstore.dart';
import '../widget/debug/cacheView.dart';
class DataCleaner {
static void cleanOldCache() async {
var cacheData = await Localstore.instance.collection(CacheView.collection).get();
cacheData?.forEach((key, value) async {
DateTime lastUpdate = DateTime.fromMillisecondsSinceEpoch(value['lastupdate']);
if(DateTime.now().subtract(const Duration(days: 200)).isAfter(lastUpdate)) {
await Localstore.instance.collection(CacheView.collection).doc(key.split('/').last).delete();
}
});
}
}