Repository: SDWebImage/SDWebImage
File: Tests/Tests/SDWebImageTestCache.m (Objective-C)

Code before:
        [self.fileManager createDirectoryAtPath:self.cachePath withIntermediateDirectories:YES attributes:nil error:nil];
    }
    return self;
}

- (void)removeAllData {
    NSURL *srcURL = [NSURL fileURLWithPath:self.cachePath isDirectory:YES];
    NSDirectoryEnumerator<NSURL *> *fileEnumerator = [self.fileManager enumeratorAtURL:srcURL
                                                  includingPropertiesForKeys:@[]
                                                                     options:(NSDirectoryEnumerationOptions)0
                                                                errorHandler:NULL];
    for (NSURL *url in fileEnumerator) {
        @autoreleasepool {
            [self.fileManager removeItemAtURL:url error:nil];
        }
    }
}

- (void)removeDataForKey:(nonnull NSString *)key {
    [self.fileManager removeItemAtPath:[self cachePathForKey:key] error:nil];
}

- (void)removeExpiredData {
    NSDate *expirationDate = [NSDate dateWithTimeIntervalSinceNow:-self.config.maxDiskAge];
    NSURL *diskCacheURL = [NSURL fileURLWithPath:self.cachePath isDirectory:YES];
    NSArray<NSString *> *resourceKeys = @[NSURLIsDirectoryKey, NSURLAttributeContentAccessDateKey];
    NSDirectoryEnumerator<NSURL *> *fileEnumerator = [self.fileManager enumeratorAtURL:diskCacheURL
                                                   includingPropertiesForKeys:resourceKeys
                                                                      options:NSDirectoryEnumerationSkipsHiddenFiles
                                                                 errorHandler:NULL];
    
    for (NSURL *fileURL in fileEnumerator) {
        @autoreleasepool {
            NSError *error;
            NSDictionary<NSString *, id> *resourceValues = [fileURL resourceValuesForKeys:resourceKeys error:&error];
            
            // Skip directories and errors.
            if (error || !resourceValues || [resourceValues[NSURLIsDirectoryKey] boolValue]) {
                continue;;
            }
            
            // Remove files that are older than the expiration date;
            NSDate *accessDate = resourceValues[NSURLAttributeContentAccessDateKey];
            if (expirationDate && [[accessDate laterDate:expirationDate] isEqualToDate:expirationDate]) {
                [self.fileManager removeItemAtURL:fileURL error:nil];
            }
        }
    }
}

- (void)setData:(nullable NSData *)data forKey:(nonnull NSString *)key {

Review comment (suggestion):
```suggestion
    NSArray<NSString *> *resourceKeys = @[NSURLIsDirectoryKey, NSURLContentAccessDateKey];
```

Code after:
        [self.fileManager createDirectoryAtPath:self.cachePath withIntermediateDirectories:YES attributes:nil error:nil];
    }
    return self;
}

- (void)removeAllData {
    NSURL *srcURL = [NSURL fileURLWithPath:self.cachePath isDirectory:YES];
    NSDirectoryEnumerator<NSURL *> *fileEnumerator = [self.fileManager enumeratorAtURL:srcURL
                                                  includingPropertiesForKeys:@[]
                                                                     options:(NSDirectoryEnumerationOptions)0
                                                                errorHandler:NULL];
    for (NSURL *url in fileEnumerator) {
        @autoreleasepool {
            [self.fileManager removeItemAtURL:url error:nil];
        }
    }
}

- (void)removeDataForKey:(nonnull NSString *)key {
    [self.fileManager removeItemAtPath:[self cachePathForKey:key] error:nil];
}

- (void)removeExpiredData {
    NSDate *expirationDate = [NSDate dateWithTimeIntervalSinceNow:-self.config.maxDiskAge];
    NSURL *diskCacheURL = [NSURL fileURLWithPath:self.cachePath isDirectory:YES];
    NSArray<NSString *> *resourceKeys = @[NSURLIsDirectoryKey, NSURLContentAccessDateKey];
    NSDirectoryEnumerator<NSURL *> *fileEnumerator = [self.fileManager enumeratorAtURL:diskCacheURL
                                                   includingPropertiesForKeys:resourceKeys
                                                                      options:NSDirectoryEnumerationSkipsHiddenFiles
                                                                 errorHandler:NULL];
    
    for (NSURL *fileURL in fileEnumerator) {
        @autoreleasepool {
            NSError *error;
            NSDictionary<NSString *, id> *resourceValues = [fileURL resourceValuesForKeys:resourceKeys error:&error];
            
            // Skip directories and errors.
            if (error || !resourceValues || [resourceValues[NSURLIsDirectoryKey] boolValue]) {
                continue;;
            }
            
            // Remove files that are older than the expiration date;
            NSDate *accessDate = resourceValues[NSURLContentAccessDateKey];
            if (expirationDate && [[accessDate laterDate:expirationDate] isEqualToDate:expirationDate]) {
                [self.fileManager removeItemAtURL:fileURL error:nil];
            }
        }
    }
}

- (void)setData:(nullable NSData *)data forKey:(nonnull NSString *)key {