Skip to content

Commit

Permalink
Remove disk cache contents one by one instead of removing and recreat…
Browse files Browse the repository at this point in the history
…ing the directory
  • Loading branch information
hpique committed Oct 4, 2014
1 parent a60d230 commit 571be17
Showing 1 changed file with 10 additions and 16 deletions.
26 changes: 10 additions & 16 deletions Haneke/HNKDiskCache.m
Expand Up @@ -119,28 +119,22 @@ - (void)removeDataForKey:(NSString*)key
- (void)removeAllData
{
dispatch_async(_queue, ^{
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error;
if ([[NSFileManager defaultManager] removeItemAtPath:_directory error:&error])
{
_size = 0;

if (![[NSFileManager defaultManager] createDirectoryAtPath:_directory withIntermediateDirectories:YES attributes:nil error:&error])
{
NSLog(@"Failed to recreate directory with error %@", error);
}
NSArray *contents = [fileManager contentsOfDirectoryAtPath:_directory error:&error];
if (!contents) {
NSLog(@"Failed to list directory with error %@", error);
return;
}
else
for (NSString *pathComponent in contents)
{
BOOL isDirectory = NO;
if (![[NSFileManager defaultManager] fileExistsAtPath:_directory isDirectory:&isDirectory])
{
_size = 0;
}
else
NSString *path = [_directory stringByAppendingPathComponent:pathComponent];
if (![fileManager removeItemAtPath:path error:&error])
{
NSLog(@"Failed to remove directory with error %@", error);
NSLog(@"Failed to remove file with error %@", error);
}
}
[self calculateSize];
});
}

Expand Down

0 comments on commit 571be17

Please sign in to comment.