0

I have been having an issue where no matter what framework i use to cache my images, from AFNetworking to SDWebImage's caching techniuqes to write to the disk. Everytime i press the home button, then go back to the app. Its like all the images have to be RE cached.

I have no clue where to start looking

In order to use both AFNetworking for my regular networking functions, such as JSON and image uploading i used https://gist.github.com/sibljon/5957892 to resolve namespace collisions so i cold totally override AFNetworkings UIImageView and stick with SDWebImage so instead of calling

Thanks to jonsibley and his answer i dont call

[imageFile setImageWithURL:[NSURL URLWithString:friendAvatar] placeholderImage:[UIImage imageNamed:@"defaultProfileImage.png"]];

im now calling (just a SD_ in front now) which allows me to override AFNetworkings caching. Correct?

[imageFile SD_setImageWithURL:[NSURL URLWithString:friendAvatar] placeholderImage:[UIImage imageNamed:@"defaultProfileImage.png"]];

EDIT UDPATE:

After much more testing i found out that the app is cleaning the cache once it RESUMES the app, NOT when it starts to get suspended (when home button is pressed) Any clue to what may be causing this?

Community
  • 1
  • 1
NodeDad
  • 1,519
  • 2
  • 19
  • 48

1 Answers1

3

Here are two possibilities. Please note the difference between clea r Disk and clea n Disk.

  1. SDWebImage calls cleanDisk upon receiving a UIApplicationWillTerminateNotification. This method removes files that are older than their expiration date. After that, it clears files from oldest to newest until the configured maximum cache size is reached.

    If you aren't setting your SDImageCache's maxCacheSize property, this property is ignored.

    If you aren't setting your SDImageCache's maxCacheAge property, it defaults to 604800 seconds (1 week).

  2. Do you have any calls to SDWebImage's clearDisk or clearMemory methods in your app? If so, set breakpoints on them to find why they're called during resume.

  3. If #1 doesn't explain it, and you never call the "clear" methods, your best bet is to set a breakpoint in [SDImageCache -cleanDisk] and step through it to see why your cache is getting cleared.
Aaron Brager
  • 65,323
  • 19
  • 161
  • 287
  • Always you to the rescue with me and these caching issues. Okay, i'll give that a shot right now and see whats going on. – NodeDad Jul 17 '13 at 23:16
  • I put a few breakpoints basically everywhere there is a clean/clear cache method called and none of them broke when pressing home button and returning to the app, i dont have any places in my code where im manually calling it either. and all the settings are at there original settings – NodeDad Jul 17 '13 at 23:33
  • If the breakpoints aren't getting hit, the `UIApplicationWillTerminateNotification` probably isn't firing - see http://stackoverflow.com/q/7370853/1445366 to make it fire in the simulator – Aaron Brager Jul 18 '13 at 14:07
  • Aside from that, the only other possibility is that they're never getting saved to disk in the first place. (You could also verify this with breakpoints.) – Aaron Brager Jul 18 '13 at 14:08
  • I need to switch to using NSUserDefaults instead of a MyClass class with a bunch of methods storing global variables, i think its just time to sit back for a minute and rethink how im doing things. All of your suggestions were a great help and got me a step further to learning more about how the caching works and i'm going to put this off for a minute until my brain blows. For now i would liek to accept your answer a it contains so much information – NodeDad Jul 18 '13 at 21:41