NSURLCache doesn't fulfill disk capacity

Originator:nicolas.suarez
Number:rdar://28518369 Date Originated:28 Sep 2016
Status:Open Resolved:No
Product:iOS Product Version:10.0.1
Classification: Reproducible:Yes
 
Area:
NSURL

Summary:
NSURLCache doesn't fulfill the limit for the disk cache, neither default value (20 MB) nor custom value, it grows indefinitely.

Steps to Reproduce:
1. Create an instance of NSURLCache and set it as shared:
    ```
    NSURLCache *cache = [[NSURLCache alloc] initWithMemoryCapacity:4 * 1024 * 1024 diskCapacity:10 * 1024 * 1024 diskPath:nil];    
    [NSURLCache setSharedURLCache:cache];
    ```
2. Create http requests using NSURLSession. Be sure that the sizes of responses pass the diskCapacity
3. Check [[NSURLCache sharedURLCache] currentDiskUsage]


Expected Results:
`currentDiskUsage` should be less or equal to `diskCapacity`

Actual Results:
`currentDiskUsage` is greater than `diskCapacity`

Version:
iOS 10.0 (14A345) - iOS 10.0.1 (14A403)

Notes:


Configuration:
iPhone 6 64 GB - iPhone 6 Simulator

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!