NodeDad
NodeDad

Reputation: 1537

Caching images doesnt stay once applicationDidEnterBackground is activated

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?

Upvotes: 0

Views: 1268

Answers (1)

Aaron Brager
Aaron Brager

Reputation: 66252

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.

Upvotes: 3

Related Questions