Question

I download few files apart from images in the server. These downloaded files are cached using TTURLCache. Over a period of time, the disk space consumed by the app can grow. For the same reason, there is a feature in the app's settings to selectively clear the cached information.

With the help of this post I am able to delete the stored files in local disk corresponding to the URL from server. This clears data from this sandbox location: "Library/Caches/Three20".

However, I observed that if I switch to offline mode, the app is still able to pull the remote resources and render data. Also, it adds back the files into "Library/Caches/Three20" location even though there is no internet connectivity! On further scrutiny, I observed that there is a cache database from where the requests are fetched:

"Library/Caches/com.yourcompany.yourapp/Cache.db" "Library/Caches/com.yourcompany.yourapp/Cache.db-shm" "Library/Caches/com.yourcompany.yourapp/Cache.db-wal"

All fine, so I tested that apart from selectively clearing the files from the location "Library/Caches/Three20" I would have to selectively remove the database entries from the db: "Library/Caches/com.yourcompany.yourapp/Cache.db", "Library/Caches/com.yourcompany.yourapp/Cache.db-shm" & "Library/Caches/com.yourcompany.yourapp/Cache.db-wal".

I checked the code, but I could not find out where exactly data is written to Cache.db and where am I supposed to clear the info in it.

Any leads would be greatly appreciated.

Was it helpful?

Solution

The Cache.db is the Cache used by Apples URL Loading System. It is no documented how it works, but it is reasonable to think that this cache will manage it's size on it's own.

Even if you remove files from Three20's cache they still live in the URL Loading Systems cache, are served from there and then readded to Three20's cache.

Find more about this cache in the URL Loading System Programming Guide

OTHER TIPS

Based on tonklon's answer and more of my research, I got to know that it was NSURLCache which was caching the responses for a URL. Also in picture was a "Permanent store" data of Restkit which too has to be cleared. So following three makes sure that we clear the data (selectively):

  1. Clear the Three20 cached files selectively only for the nodes for which you do not want cached information in the sandbox anymore (From https://stackoverflow.com/a/5161356/260665): It clears data from "Library/Caches/Three20"

    [[TTURLCache sharedCache] removeURL:@"http://example.com/an_image.jpg" fromDisk:YES]; [[TTURLCache sharedCache] invalidateURL:@"http://example.com/an_image.jpg"];

  2. Clear Restkit caches: (From the author of Restkit: https://stackoverflow.com/a/7230083/260665) It clears data from "Library/Caches/RKClientRequestCache-youapp.com/PermanentStore" & "Library/Caches/RKClientRequestCache-yourapp.com/SessionStore"

    [[RKClient sharedClient].requestCache invalidateAll];
    
  3. Clear the NSURLCache information. It clears data from "Library/Caches/com.yourcompany.yourapp/Cache.db-wal" (http://twobitlabs.com/2012/01/ios-ipad-iphone-nsurlcache-uiwebview-memory-utilization/)

    [[NSURLCache sharedURLCache] removeAllCachedResponses];
    NSUInteger originalDiskCapacity = [[NSURLCache sharedURLCache] diskCapacity];
    [[NSURLCache sharedURLCache] setDiskCapacity:0];
    [[NSURLCache sharedURLCache] setDiskCapacity:originalDiskCapacity];
    
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top