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?
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.
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.
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.
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
}];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With