packages.flutter icon indicating copy to clipboard operation
packages.flutter copied to clipboard

Creating duplicate files in cache with unique file names

Open nachikamod opened this issue 4 years ago • 9 comments

As it seems when I try to load an PDF from assets. The Widget creates an copy of the file with unique file name as a cache in app folder.

But as I can see if we reopen the same PDF it creates the duplicate of that same file with new file name. Which results in unnecessary feeling of memory in the cache.

I did not found any inbuilt way in the library itself to get rid of that cache or to validate if that file already present in the cache.

I am attaching detailed Screen shots what I am trying to explain

Screenshot_20210320-113802 As you can see I am trying to open this image two times.

D/PDF_RENDER(10331): OpenAssetDocument. Created file: /data/user/0/com.mahayoga.user/cache/59abc52f7cbe4e0fae57c6f6e25d744d.pdf
D/PDF_RENDER(10331): OpenFileDocument. File: /data/user/0/com.mahayoga.user/cache/59abc52f7cbe4e0fae57c6f6e25d744d.pdf
D/PDF_RENDER(10331): OpenAssetDocument. Created file: /data/user/0/com.mahayoga.user/cache/ee6e681802fa426cbb236c7d8b632a18.pdf
D/PDF_RENDER(10331): OpenFileDocument. File: /data/user/0/com.mahayoga.user/cache/ee6e681802fa426cbb236c7d8b632a18.pdf

Which results in creation of this much duplication if we don't handle cache manually

Screenshot from 2021-03-20 17-17-15

So If there some issue from side to understand the documentation please show me the right direction else. Please provide an inbuilt method to manage duplication.

nachikamod avatar Mar 20 '21 06:03 nachikamod

Any replies on this ?

nachikamod avatar May 21 '21 08:05 nachikamod

I need to be sure cached documents are disposed when disposing the pdf-renderer. Any news here?

ilaurillard avatar Jun 17 '21 07:06 ilaurillard

@nachikamod Did you find any solution? I'm facing the same problem.

Firas-Amin avatar Jan 24 '22 00:01 Firas-Amin

Not in the library @Firas-Amin but I implemented a crude (Brute force approach) solution. Which basically reads the cache and clears all the pdf files. Now since we can't know the file name saved in the cache, because the library saves this file in the cache with randomly generated names, I delete all the cache pdf files instead.


// Run this two lines before opening any pdf file
String _cacheDir = (await getTemporaryDirectory()).path;
new Directory(_cacheDir).delete(recursive: true);

// Open pdf file here


So, this is simple implementation you can employ with path_provider package which basically reads application's cache directory and delete all the contents. But you can modify this by reading the directory and only deleting the pdf files unlike I am clearing out all the cache (Cause, my application didn't required file caching so only thing was caching was of from this library).

nachikamod avatar Jan 24 '22 05:01 nachikamod

Thank you for the code @nachikamod. For some reasons, it seems it doesn't clear the cache while navigating between pages. For example, I have a PDF file with 80mb size. When the user starts the application, 80mb cache added to the application and when they go to the index and pick different page from the PDF and navigate to it another 80mb added .

Firas-Amin avatar Jan 25 '22 02:01 Firas-Amin

Let's connect on discord

nachikamod avatar Jan 25 '22 05:01 nachikamod

Check my request as 4RB1TR4RY#1264

nachikamod avatar Jan 25 '22 14:01 nachikamod

Any updates on this? This is important

cstsortan avatar Sep 09 '22 08:09 cstsortan

Any updates on this? This is important

No updates yet from the maintainer.

nachikamod avatar Sep 09 '22 09:09 nachikamod