Browse Source

Cache downloaded thumbnails and files for 365 days

Vishnu Mohandas 4 years ago
parent
commit
735d30583a
1 changed files with 14 additions and 5 deletions
  1. 14 5
      lib/utils/file_util.dart

+ 14 - 5
lib/utils/file_util.dart

@@ -153,8 +153,13 @@ Future<io.File> _downloadAndDecrypt(File file, BaseCacheManager cacheManager,
         await CryptoUtil.decryptFileToData(temporaryPath, file.getPassword());
         await CryptoUtil.decryptFileToData(temporaryPath, file.getPassword());
     io.File(temporaryPath).deleteSync();
     io.File(temporaryPath).deleteSync();
     final fileExtension = extension(file.title).substring(1).toLowerCase();
     final fileExtension = extension(file.title).substring(1).toLowerCase();
-    return cacheManager.putFile(file.getDownloadUrl(), data,
-        fileExtension: fileExtension);
+    return cacheManager.putFile(
+      file.getDownloadUrl(),
+      data,
+      eTag: file.getDownloadUrl(),
+      maxAge: Duration(days: 365),
+      fileExtension: fileExtension,
+    );
   });
   });
 }
 }
 
 
@@ -162,11 +167,15 @@ Future<io.File> _downloadAndDecryptThumbnail(File file) async {
   final temporaryPath = Configuration.instance.getTempDirectory() +
   final temporaryPath = Configuration.instance.getTempDirectory() +
       file.generatedID.toString() +
       file.generatedID.toString() +
       "_thumbnail.aes";
       "_thumbnail.aes";
-  Dio dio = Dio();
-  return dio.download(file.getThumbnailUrl(), temporaryPath).then((_) async {
+  return Dio().download(file.getThumbnailUrl(), temporaryPath).then((_) async {
     final data =
     final data =
         await CryptoUtil.decryptFileToData(temporaryPath, file.getPassword());
         await CryptoUtil.decryptFileToData(temporaryPath, file.getPassword());
     io.File(temporaryPath).deleteSync();
     io.File(temporaryPath).deleteSync();
-    return ThumbnailCacheManager().putFile(file.getThumbnailUrl(), data);
+    return ThumbnailCacheManager().putFile(
+      file.getThumbnailUrl(),
+      data,
+      eTag: file.getThumbnailUrl(),
+      maxAge: Duration(days: 365),
+    );
   });
   });
 }
 }