开发者

Managing iPhone app sandbox tmp directory size for caching images

开发者 https://www.devze.com 2023-01-16 13:56 出处:网络
I have a fairly image-intensive iPhone app, and I\'m loo开发者_C百科king to store remotely downloaded images locally in the app\'s sandbox tmp directory to avoid unnecessary network requests. Is there

I have a fairly image-intensive iPhone app, and I'm loo开发者_C百科king 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号