Empty the cache programmatically in iOS

余生长醉 提交于 2019-12-07 02:26:46

问题


Does anyone by coincidence know how I can empty the cache memory of the iOS app that I am developing, in the moment it goes to the background (applicationDidEnterBackground)? I have investigated about NSCache but I am still not able to understand how could I retrieve the cache to basically remove/free it?


回答1:


Is this what you're talking about?

[[NSURLCache sharedURLCache] removeAllCachedResponses];

You can also modify the cache behavior of your requests to selectively cache responses. If you're using AFNetworking by chance, you can use setCacheResponseBlock. E.g. in one project I set it to return nil for all large video and audio files. But allow it to cache smaller image files.

[streamingOperation setCacheResponseBlock:^NSCachedURLResponse *(NSURLConnection *connection, NSCachedURLResponse *cachedResponse) {
    return nil; // Ensures we are not unecessarily caching asset data to Cache.db
}];


来源:https://stackoverflow.com/questions/17581221/empty-the-cache-programmatically-in-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!