How to check amount of cached disk space used on iPhone - 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.

Related

How long do image_picker images stay in cache?

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()

why do we need page cache when there is virtual memory

simple question about os. I know virtual memory handle the memory mapping for us. When some data we need is not in memory, VM will page in and copy the data into main memory, and if we are short of memory it will also page out some obsolete memory to disk. My question is, since virtual memory already handle this, why do we need a page cache? It seems to me VM already make main memory a cache for disk.
Virtual memory: see all address space (ram) as my own and bigger than the actual memory (swap to disk as necessary);
Page cache: open a file that is stored in some drive (a filesystem thing)

Document directory is good to store data or cache in objective c?

Friends i need to store more than 100 mb data which come in zip format and i get data after unzip this zip file and unzip data is more than 70 mb in size , so my question is that which storage location is good to keep this data, currently i am using cache but it gives memory warning on device when i writes data in cache and then after sometimes app gets crashed.
This zip file contain html pages and images.
i checked this link also but did't get answer to store thes html and images which comes in zip format from server.
Any small help will be highly appreciated.
Thanks in advance
Don't try to read this entire ZIP file into memory at once! It's not the permanent storage (Flash) on the device which goves you the memory warning, but you eat up the RAM. Yes, the Documents or Library directory is fine for storing your app data, just be careful with the memory management.
Like H2CO3 stated, the memory warning is indeed caused by reading it all into RAM in one chunk. Apart from that, be sure to follow Apple's guidelines regarding data storage. If the data being saved is temporary, be sure not to store it in your documents directory, otherwise your application might get rejected (Speaking from experience).

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)