clearCache method
Implementation
Future<void> clearCache() async {
for (var pathStr in files()) {
var name = Path.basename(pathStr);
name = name.replaceAll(".log", "");
if (DateTime.tryParse(name) != null &&
DateTime.parse(name)
.isBefore(DateTime.now().subtract(Duration(hours: _hours * 2)))) {
await File(pathStr).delete();
} else if ((int.tryParse(name) ?? 0) > 0) {
int time = int.tryParse(name) ?? 0;
if (DateTime.fromMillisecondsSinceEpoch(time)
.isBefore(DateTime.now().subtract(Duration(hours: _hours * 2)))) {
await File(pathStr).delete();
}
}
}
}