-
-
Notifications
You must be signed in to change notification settings - Fork 6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom image cache search paths #156
Conversation
…ths for images that have been previously cached with SDWebImage. This is particularly useful in cases where you may be bundling images that have been previously cached with SDWebImage. The need to copy those images over into the 'ImageCache' folder can be eliminated
@@ -221,6 +236,23 @@ - (void)queryDiskCacheOperation:(NSDictionary *)arguments | |||
|
|||
#pragma mark ImageCache | |||
|
|||
- (void)addCustomImageSearchCachePath:(NSString*)path | |||
{ | |||
[userCachePaths addObject:path]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might want to consider guarding against the same path being added multiple times. While that's probably a user error, it's easy enough to be extra helpful.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks.
Going to try and update this soon for the new 3.0 SDWebImage as this PR was based on the last version, will take your suggestion into account!
Adds public method for adding custom cache paths Breaks apart default cache path and file name generation method Add in support for the demo to demonstrate loading a gif from a path that is bundled with the app when built
@rs I've finally updated this for the latest SDWebImage! I updated the demo as well to show how adding a custom path works, and bundled one of the images with the app (the gif to be specific) |
@rs any chance this will get looked at/merged in? We've been using it in production smoothly for a few weeks now, would love to get it official! |
Merged |
@SRandazzo Could you help a newbie out? How do you go about seeding your app with images? |
@timmolter Of course! It's important that any images you want to "seed" are downloaded via SDWebImage (since SDWebImage manages generating the hash/file name based on the URL of the images) To go about this, start with a fresh/clean cache (you can use the SDImageCache method, or just manually delete the files), then download all the images you need. For example, we sometimes just use an array of image URLs that we loop through and tell SDWebImage download. If your app is not user data specific, you can also just run through it, and any images downloaded will be in the cache folder (again, be careful of user data specific images) It's not a bad idea to have a completely separate target that can run this code if you are going to do it often Once all the images you need are downloaded, navigate in your Finder to here: Copy all the files inside of the I use something like "seed_image" for the folder name, then added that to the project (In this case, I typically add as a "folder reference") from there, just use this code (in the PR/sample project) NSString *bundledPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"seed_image"];
[[SDImageCache sharedImageCache] addReadOnlyCachePath:bundledPath]; Obviously this could all stand to be automated, but we weren't swapping bundled images often enough to make it worth it hope that helps |
@SRandazzo Wow! Thanks so much! I'll give it a shot. |
@SRandazzo God dang brilliant! Thanks for this! |
This feature lets you define custom paths for SDWebImage to search for previously-cached-images.
This is particularly useful if you are bundling images with your app that have been cached by SDWebImage. (ie. if you are 'seeding' your app with a core-data file that contains a lot of URL's to images and would like to also seed those images without having to copy every one of them over)
For example, you can tell SDImageCache to add '[[NSBundle mainBundle] resourcePath]' as a custom path, so that the main bundle will be queried for cached images.
This prevents the need for you to copy pre-cached images over to the caches/ImageCache folder that SDImageCache normally checks for.
The custom paths are read-only.