This repository was archived by the owner on Jan 17, 2023. It is now read-only.
[AFImageDownloader defaultURLCache] is broken and can exceed disk cache limit#4737
Open
congsun wants to merge 1 commit intoAFNetworking:masterfrom
Open
[AFImageDownloader defaultURLCache] is broken and can exceed disk cache limit#4737congsun wants to merge 1 commit intoAFNetworking:masterfrom
congsun wants to merge 1 commit intoAFNetworking:masterfrom
Conversation
Author
|
@jshier This is a pretty critical bug and it's causing the iOS app cache size out of control if they use |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Goals ⚽
This fixes an issue introduced in #4523
In Apple's documentation, the diskPath in
[NSURLCache initWithMemoryCapacity:diskCapacity:diskPath:]isIn existing code, we're feeding the entire path (including the absolute cache path), and the absolute path of our cache directory will be like
/CACHE_DIR/CACHE_DIR/com.alamofire.imageDownloader. This will break because the absolute path to the cache directory can change and it's observed during app upgrade. After the path change, there will be a new cache directory created, and we won't be able to hit cache with NSURLCache in the previous path, what's worse is this will exceed the disk cache size limit as NSURLCache will only check the size for the diskPath it initialized with.See below screenshot for an example

Implementation Details 🚧
The newer initializer (used in
#if TARGET_OS_MACCATALYST)initWithMemoryCapacity:diskCapacity:directoryURL:indeed asks for absolute path, so we will not touch that. But in the initializer usingdiskPathonly pass in thediskPathrather than the absolute path to the cache directory.Testing Details 🔍
After the change, the NSURLCache control of the total disk size limit is fixed and we're hitting caches more frequently.