File tree 2 files changed +17
-0
lines changed
2 files changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -675,6 +675,10 @@ - (void)setObject:(id <NSCoding>)object forKey:(NSString *)key fileURL:(NSURL **
675
675
676
676
NSNumber *diskFileSize = [values objectForKey: NSURLTotalFileAllocatedSizeKey ];
677
677
if (diskFileSize) {
678
+ NSNumber *prevDiskFileSize = [self ->_sizes objectForKey: key];
679
+ if (prevDiskFileSize) {
680
+ self.byteCount = self->_byteCount - [prevDiskFileSize unsignedIntegerValue ];
681
+ }
678
682
[self ->_sizes setObject: diskFileSize forKey: key];
679
683
self.byteCount = self->_byteCount + [diskFileSize unsignedIntegerValue ]; // atomic
680
684
}
Original file line number Diff line number Diff line change @@ -241,6 +241,19 @@ - (void)testDiskByteCount
241
241
XCTAssertTrue (self.cache .diskByteCount > 0 , @" disk cache byte count was not greater than zero" );
242
242
}
243
243
244
+ - (void )testDiskByteCountWithExistingKey
245
+ {
246
+ [self .cache setObject: [self image ] forKey: @" image" ];
247
+ NSUInteger initialDiskByteCount = self.cache .diskByteCount ;
248
+ [self .cache setObject: [self image ] forKey: @" image" ];
249
+
250
+ XCTAssertTrue (self.cache .diskByteCount == initialDiskByteCount, @" disk cache byte count should not change by adding object with existing key and size" );
251
+
252
+ [self .cache setObject: [self image ] forKey: @" image2" ];
253
+
254
+ XCTAssertTrue (self.cache .diskByteCount > initialDiskByteCount, @" disk cache byte count should increase with new key and object added to disk cache" );
255
+ }
256
+
244
257
- (void )testOneThousandAndOneWrites
245
258
{
246
259
NSUInteger max = 1001 ;
You can’t perform that action at this time.
0 commit comments