old cache gets deleted #52

Merged
MineTec merged 3 commits from develop-removeOldCache into develop 2024-04-02 07:34:06 +00:00
3 changed files with 20 additions and 2 deletions

View File

@ -14,6 +14,7 @@ import 'api/mhsl/server/userIndex/update/updateUserindex.dart';
import 'model/breakers/Breaker.dart';
import 'model/breakers/BreakerProps.dart';
import 'model/chatList/chatListProps.dart';
import 'model/dataCleaner.dart';
import 'model/timetable/timetableProps.dart';
import 'notification/notificationController.dart';
import 'notification/notificationTasks.dart';
@ -87,6 +88,8 @@ class _AppState extends State<App> with WidgetsBindingObserver {
FirebaseMessaging.onMessageOpenedApp.listen((message) => NotificationController.onAppOpenedByNotification(message, context));
FirebaseMessaging.instance.getInitialMessage().then((message) => message == null ? null : NotificationController.onAppOpenedByNotification(message, context));
DataCleaner.cleanOldCache();
super.initState();
}

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();
}
});
}
}

View File

@ -11,7 +11,7 @@ import '../../../widget/placeholderView.dart';
import 'jsonViewer.dart';
class CacheView extends StatefulWidget {
final collection = 'MarianumMobile';
static String collection = 'MarianumMobile';
const CacheView({super.key});
@override
@ -34,7 +34,7 @@ class _CacheViewState extends State<CacheView> {
@override
void initState() {
files = Localstore.instance.collection(widget.collection).get();
files = Localstore.instance.collection(CacheView.collection).get();
super.initState();
}