-
-
Notifications
You must be signed in to change notification settings - Fork 518
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
Disk Cache: Add a Sensible Default for Key Encoder #160
Comments
Hey @AndrewBarba. Yes, you do need to use one of the cryptographic hash functions which guarantee that the probability of two URLs having the same hash value (which is used as a filename) is so low that you can ignore it. The Another alternative that I've explored is percent encoding URLs to produce valid filenames. The problem with that approach is that filenames have size limits. The maximum filename size on HFS+ is 255 characters and I'm not yet sure what the limit is on APFS. |
There is another option, if you know that you can extract some ID from a URL which uniquely identifies an image and can be used as a filename (or you can percent encode it if necessary), you can use it as a filename. |
I thought about doing that but most of the images I'm using are going through a service like Imgix which has sizing params in the url so the id doesn't do me much good. Thanks for the explanation though! Will most likely stick with sha1 for now. Feel free to close or rename if you end up exploring other options |
I also use Apple's pure Swift implementation of SHA256 in a few other projects, not sure if this is helpful here to lower the barrier to entry: swift-package-manager/SHA256.swift I just remove the ImagePipeline.shared = ImagePipeline {
$0.enableExperimentalAggressiveDiskCaching { SHA256($0).digestString() }
} |
Yep, this is perfect. I’m going to provide a sensible default in one of the upcoming versions. |
It would be nice to add a default hash function to the project. The SHA256 from the SPM project takes almost a whole second to compile. And I haven't tested how fast it is.
|
I don’t have hard numbers for you, but the app I work on (recently updated to nuke 7, disk cache with sha256) has been scrolling with no hiccups at all. In the main table view there are 3 images loaded by nuke per cell and it fits 4 cells on screen. The perceived performance has been excellent. |
I'm not really expecting any differences in perceived performance, but I prefer to use the fastest stuff available anyway 😃 The compile time is a real concern though. I wouldn't want users to measure compile time at some point and find out that there are some Nuke's functions at the top (700 ms for a single function is a lot). |
Yes totally get it. And that’s why I use Nuke over everything else :) |
Swift 4.2 finally seems to come with |
I've implemented a default |
In the current example for
enableExperimentalAggressiveDiskCaching
you are using a sha1 hash as the filename based on the images url, can you think of any reason we can't just useString.hashValue
? Asking because it's just more accessible in my opinionThe text was updated successfully, but these errors were encountered: