diff --git a/TMCache/TMMemoryCache.m b/TMCache/TMMemoryCache.m index 17c56a4..e8f53f7 100644 --- a/TMCache/TMMemoryCache.m +++ b/TMCache/TMMemoryCache.m @@ -286,6 +286,10 @@ - (void)setObject:(id)object forKey:(NSString *)key withCost:(NSUInteger)cost bl if (strongSelf->_willAddObjectBlock) strongSelf->_willAddObjectBlock(strongSelf, key, object); + NSNumber *oldCost = [strongSelf->_costs objectForKey:key]; + if (oldCost) + _totalCost -= [oldCost unsignedIntegerValue]; + [strongSelf->_dictionary setObject:object forKey:key]; [strongSelf->_dates setObject:now forKey:key]; [strongSelf->_costs setObject:@(cost) forKey:key];