开发者

When should we delete the cache data in an iPhone apps?

We often cache image and data to improve our iPhone app's performance. But what strategy do you use to mana开发者_如何学运维ge the cache data, such as delete or update it?

I saved the images to TMP folder, but don't know when should I trigger to "checking out of date cache data and delete it": when the iPhone apps starts, or quits, or in idle time?


You should delete the cache when the iPhone invokes your "didReceiveMemoryWarning" function.


When the application launches or quits, the user is usually expecting responsiveness. Choose a minimum amount of real time, like 24 hours, and a minimum amount of idle time, like a minute. If the user has been idle for a minute and it is more than 24 hours from the last cache purge, then clean the cache. If you are keeping track of how much data is cached, then you could factor that in as well. If it has been more than 24 hours and/or there is more than a megabyte in the cache.

If you are sure the application is being quit normally, as opposed to being quit to answer a call or launch another application, then that might also be a good time.

If your application does something that the user has to wait for anyway, but that would not be affected by purging the cache, then that might also be a good time. For example, fetching some data from a server.


Appreciate for your responses. I agree that checking for delete the cache at the start or quit time will reduce the program's performance. Moreover, quit time is also used for saving the program's state.

The idea to check for idle time in 1 min is quite ok, but I have to build mechanism to check idle for every 15 s during the application time. I don't think it's easy and good for performance.

At last, I decide to perform "check and delete cache" after I retrieve new Items (data + image). I will check for items (data +image) that doesn't need to be displayed anymore and delete it. I think it makes sense that the feature who saves the cache, will deletes the cache also. Certainly, I will do this in another thread to avoid frozen the interface.

Is this good? Pls give me your opinions.


I personally dosn't like if cache is cleaned when i open a application or idle longer then about 1 minute. The idea cleaning if age of the cache is about 24hours is good.

My personal recommandation is to build stack of cache files. And then checking for the cache file creation/modification time or last cache file access. So clean in background (don't let become your app feel slow cause you're doing such tasks when starting or stopping an app) maybe in a thread (does iphone sdk support that? dont know :)) and check for "is cache file older then 24hrs? if yes > recache or delete file

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜