How long do image_picker images stay in cache? - flutter

Do they stay until the app is uninstalled or cache is cleared, or do the images get deleted at certain times by the os?

It depends on the space available on the device to auto delete.
Please check the link below for more info
Apps are strongly encouraged to keep their usage of cache space below the quota returned by StorageManager#getCacheQuotaBytes(java.util.UUID). If your app goes above this quota, your cached files will be some of the first to be deleted when additional disk space is needed. Conversely, if your app stays under this quota, your cached files will be some of the last to be deleted when additional disk space is needed.
https://developer.android.com/reference/android/content/Context.html#getCacheDir()

Related

Used space displayed for my Google disk is 4 times more than total size of the stored files

As it follows from the notification displayed, I have used almost all available Google disk space (96%) while the total size of the files are 3.5 Gb only. Additional 1Gb was deleted and stored in the bin. What is the reason an how can I fix it? Also I have a lot of files shared with me from other accounts. But regarding Google Disk documentation they should not be taken into account. Additionally I have 0.8GB in Gmail and no files in Google photo
Go to this link and evaluate what are the files that are consuming more storage
Delete the files in your bin, as they are still counting towards your quota
After you delete the files, it usually takes some time to update the space on your Drive. A propagation matter.
Make sure you don't have a lot of photos taking quota out of your account

Does Firestore ever purge its own document cache?

Assume every time an app launches, a listener is attached to a certain document in Firestore. Is it safe to assume that this document will always be available in the cache should the app ever go offline given that a listener is always attached to it? Does Firestore cache some documents with higher priority like this one because they are always accessed? And does Firestore ever purge this cache behind the scenes?
I ask because I have the option to backup this data to disk on the client but wonder if it's even necessary—when would this backup ever really be used?
Documents do not stay in cache forever. The cache has a maximum size, and if a new document in cache would cause that limit to be exceeded, old documents will be evicted from cache. The cache could also be purged by the user if they clear the app's data. According to the documentation:
When persistence is enabled, Cloud Firestore caches every document received from the backend for offline access. Cloud Firestore sets a default threshold for cache size. After exceeding the default, Cloud Firestore periodically attempts to clean up older, unused documents. You can configure a different cache size threshold or disable the clean-up process completely.
If you must have a document available locally at all times, you should implement your own persistent storage to get that guarantee.
To read more about how the cache works, read this post.

How to check amount of cached disk space used on iPhone

So the OS basically removes all disk memory in the cached directory of apps when disk space runs low, is there any way of determining how much disk space is currently being used for cached data?
No.
You can never access the file system in general. And thus not the cache being used by other apps.
If you re-ask the question as "Is there any way to tell how much disk space my app is using in the cache, the answer is yes.
Walk the file system of your cache directory using NSFileManager and use [NSFileManager attributesOfItemAtPath:error:] to get the size of each file.

Managing iPhone app sandbox tmp directory size for caching images

I have a fairly image-intensive iPhone app, and I'm looking to store remotely downloaded images locally in the app's sandbox tmp directory to avoid unnecessary network requests. Is there a limit to the total size of the files stored in an app's directories, or does the app need to manage that? How would the app determine the size of the files in the tmp directory?
Also, if the app needs to manage the size of the cache, I'd like to implement some kind of cache policy to determine which files get invalidated. How would I go about doing this? If I want to implement a basic LRU caching policy - invalidating files that have been used least recently - it seems like I would need to store access counts for each image and store that on the disk as well, which seems kind of funky. I suppose an easy size management policy would be to simply completely wipe the cache each time the application terminates.
Also, what's the difference between using the directory from NSCachesDirectory versus NSTemporaryDirectory? The Apple docs mention both, but don't talk about which one to use for what type of files. I'm thinking the NSTemporaryDirectory is more like a Unix /var/tmp directory, and used for ephemeral data that can be wiped out at anytime. Seems to me the NSCachesDirectory is more appropriate for storing cached images, since the files could be needed across multiple app lifecycles.
All temporary directories are local to your application; any of them will work and there is no artificial limit to the size of their contents.
A persistent LRU cache policy should be both sufficient and relatively easy to implement.

Reserving Disk Space on iPhone

I want to be able to 'reserve' a set amount of disk space on my iPhone for my particular application. Before I get flamed I should add this is NOT for a public application.
I assume the simplest way to do this is to actually create blocks of files up to the space I wish to reserve and then delete and use these blocks as necessary.
Is there any filesystem operation which might allow me to do this without actually having to write content for all the space I want to allocate? I'm asking this because I'm not sure lazy the disk space allocator might be.
No, this is something well outside the SDK. You'll have to create your own methods to handle this for you.
iTunes ensures there's at least 200MB available after every sync. It's only the users who don't sync regularly that can cause issues (and even then they are prompted to free up space when they go below 50MB free).
Instead of reserving space, why not simply pop up an alert when disk space is low? (and enter a feature reduced mode)