开发者

How to clean catched data after some days in iPhone using Objective-c?

I am working on a project of iPhone through Objective-c. My project stores some data and files permanently in the iPhone which get useless after some days. For example, I am implementing catching to save some images which get used by application again and again such that to increase its speed and reduce downloading time when require. But After some days those images become useless but stay in the phone memory. I want make some logic in such a manner that when we start the application then it first detects t开发者_如何学编程he useless data and then clean it in background thread or at closing of the application.

Please tell me the "How can I achieve this".

Thanks in advance


You already mention your solution.

Pseudocode:

for (CacheData data in cache)
   if (noLongerRelevant(data))
      delete(data)

BTW, you really should start accepting answers. This is just how this site works. Please also revisit your old questions.


If you want to count the number of days elapsed then you can save the time in the NSUserDefaults and compare with the current date and delete the cached images.

If you want to count the number of times the app has been started then you can use NSUserDefaults again.

Both the piece of code has to be written in your app delegate class in the method appdidfinishlaunching.

For more complex scenarios also the same can be followed which is basically storing the start count and comparing each time untill a limit is reached when the cache can be cleared.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜