2022-10-19 22:03:54 +02:00
|
|
|
import 'dart:io';
|
|
|
|
|
|
|
|
import 'package:path_provider/path_provider.dart';
|
|
|
|
|
2023-03-04 00:38:30 +02:00
|
|
|
@Deprecated("only kept to remove its files after migration")
|
2022-10-19 22:03:54 +02:00
|
|
|
abstract class JsonCache<T> {
|
|
|
|
final String cacheFileName;
|
|
|
|
|
|
|
|
JsonCache(this.cacheFileName);
|
|
|
|
|
|
|
|
Future<File> _getCacheFile() async {
|
|
|
|
final basePath = await getTemporaryDirectory();
|
|
|
|
final basePathName = basePath.path;
|
|
|
|
|
|
|
|
final file = File("$basePathName/$cacheFileName.bin");
|
|
|
|
|
|
|
|
return file;
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<bool> isValid() async {
|
|
|
|
final file = await _getCacheFile();
|
|
|
|
return await file.exists();
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> invalidate() async {
|
2022-11-28 18:01:09 +02:00
|
|
|
try {
|
|
|
|
final file = await _getCacheFile();
|
|
|
|
await file.delete();
|
|
|
|
} on FileSystemException {
|
|
|
|
// file is already deleted
|
|
|
|
}
|
2022-10-19 22:03:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void put(T data);
|
2023-02-04 22:42:42 +02:00
|
|
|
Future<T?> get();
|
2022-11-28 18:01:09 +02:00
|
|
|
}
|