8000 [AFImageDownloader defaultURLCache] is broken and can exceed disk cache limit by congsun · Pull Request #4737 · AFNetworking/AFNetworking · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
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
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

congsun
Copy link
@congsun congsun commented Jan 13, 2022

Goals ⚽

This fixes an issue introduced in #4523

In Apple's documentation, the diskPath in [NSURLCache initWithMemoryCapacity:diskCapacity:diskPath:] is

the name of a subdirectory of the application’s default cache directory in which to store the on-disk cache (the subdirectory is created if it does not exist).

In 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
image

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 using diskPath only pass in the diskPath rather 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.

@congsun
Copy link
Author
congsun commented Jan 13, 2022

@jshier This is a pretty critical bug and it's causing the iOS app cache size out of control if they use AFImageDownloader. Could we get this fix in soon?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant
0