Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Empty the cache programmatically in iOS

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?

like image 521
Stefan S Avatar asked Jul 10 '13 21:07

Stefan S


People also ask

How do I access iOS cache?

Go to Settings > General > [Device] Storage. You may see a list of recommendations for optimising your device's storage, followed by a list of installed apps and the amount of storage each one uses. Tap an app's name for more information about its storage. Cached data and temporary data may not be counted as usage.

How do I manually clear app cache?

Clear an app's cache It will get rid of residual files that could be slowing down the app. Open Settings, and then swipe to and tap Apps. Select or search for the app you want to clear. Tap Storage, and then tap Clear cache.

What is caching in iOS?

Content caching speeds up downloading of software distributed by Apple and data that users store in iCloud by saving content that local Mac computers, iOS and iPadOS devices, and Apple TV devices have already downloaded.


1 Answers

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
}];
like image 197
Alfie Hanssen Avatar answered Oct 10 '22 16:10

Alfie Hanssen