old cache gets deleted #52
@ -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();
|
||||
}
|
||||
|
||||
|
15
lib/model/dataCleaner.dart
Normal file
15
lib/model/dataCleaner.dart
Normal 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();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -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();
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user