fromDefault static method

Future<FileCache> fromDefault({
  1. Loader loader = defaultLoader,
  2. String? path,
  3. bool scan = false,
})

We can provider capabity for multi instance. This function ONLY for convenience

Implementation

static Future<FileCache> fromDefault({
  Loader loader = defaultLoader,
  String? path,
  bool scan = false,
}) async {
  if (_instance == null) {
    final Completer<FileCache> completer = Completer<FileCache>();
    if (path == null) {
      Directory dir = await getTemporaryDirectory();
      path = "${dir.path}/cache2";
    }

    final fileCache = FileCache(
      path: path,
      loader: loader,
    );

    if (scan) {
      fileCache.scanFolder().then((ScanResult res) {
        print("FileCache in scan, delete ${res.deleteCount} file.");
        fileCache.stats.bytesInFile = res.bytes;
        completer.complete(fileCache);
      });
    } else {
      completer.complete(fileCache);
    }
    _instance = completer.future;
  }
  return _instance!;
}