0

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.

Community
  • 1
  • 1
Raj Pawan Gumdal
  • 7,390
  • 10
  • 60
  • 92

2 Answers2

1

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

tonklon
  • 6,777
  • 2
  • 30
  • 36
1

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];
    
Community
  • 1
  • 1
Raj Pawan Gumdal
  • 7,390
  • 10
  • 60
  • 92
  • 1
    That looks about right to me. But have you thought about disabling the NSURLCache completely? If you are using Three20's and RestKit's cache that should do it. – tonklon Sep 12 '13 at 07:04
  • I am clearing NSURLCache's content coz I observed that all the data is still there with the NSURLCache. Even though I delete files from cache it is not making difference as all the data is already cached. After clearing the NSURLCache I could see that all data is erased. However, I am resetting the 'originalDiskCapacity' this does not seem to make any impact. I observed that the data is not cached in 'Cache.db-wal' file anymore. Any idea about this? – Raj Pawan Gumdal Sep 12 '13 at 17:29