Skip to content

Commit

Permalink
Fix incorrect byteCount tracking
Browse files Browse the repository at this point in the history
Decrease byteCount by file's previous byteCount if updating object already in cache.
  • Loading branch information
rewcraig committed Sep 23, 2015
1 parent 3d03a98 commit 40cc76d
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions PINCache/PINDiskCache.m
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,10 @@ - (void)setObject:(id <NSCoding>)object forKey:(NSString *)key fileURL:(NSURL **

NSNumber *diskFileSize = [values objectForKey:NSURLTotalFileAllocatedSizeKey];
if (diskFileSize) {
NSNumber *prevDiskFileSize = [self->_sizes objectForKey:key];
if (prevDiskFileSize) {
self.byteCount = self->_byteCount - [prevDiskFileSize unsignedIntegerValue];
}
[self->_sizes setObject:diskFileSize forKey:key];
self.byteCount = self->_byteCount + [diskFileSize unsignedIntegerValue]; // atomic
}
Expand Down

0 comments on commit 40cc76d

Please sign in to comment.