我使用SDwebimage框架来缓存图像,所以下载图像的数量每天都在增加,所以在使用应用程序3-4天后,缓存会增加,从而导致应用程序性能下降,是否存在提高性能的问题?
发布于 2015-06-28 06:27:17
看看这个,所以发布here
您可以设置缓存持续时间的时间段,然后刷新缓存。此外,您还可以在maxCacheSize中使用SDImageCache.m中的cleanDiskWithCompletionBlock值。
// If our remaining disk cache exceeds a configured maximum size, perform a second
// size-based cleanup pass. We delete the oldest files first.
if (self.maxCacheSize > 0 && currentCacheSize > self.maxCacheSize) {
// Target half of our maximum cache size for this cleanup pass.
const NSUInteger desiredCacheSize = self.maxCacheSize / 2;
// Sort the remaining cache files by their last modification time (oldest first).
NSArray *sortedFiles = [cacheFiles keysSortedByValueWithOptions:NSSortConcurrent
usingComparator:^NSComparisonResult(id obj1, id obj2) {
return [obj1[NSURLContentModificationDateKey] compare:obj2[NSURLContentModificationDateKey]];
}];
// Delete files until we fall below our desired cache size.
for (NSURL *fileURL in sortedFiles) {
if ([_fileManager removeItemAtURL:fileURL error:nil]) {
NSDictionary *resourceValues = cacheFiles[fileURL];
NSNumber *totalAllocatedSize = resourceValues[NSURLTotalFileAllocatedSizeKey];
currentCacheSize -= [totalAllocatedSize unsignedIntegerValue];
if (currentCacheSize < desiredCacheSize) {
break;
}
}
}
}发布于 2018-05-30 13:56:20
您可以简单地为共享的SDImageCache实例设置一个全局缓存值。
只需在AppDelegate上调用以下命令:
// limit SDImage cache to 50 MGB
SDImageCache.shared().config.maxCacheSize = 1_000_000 * 50
https://stackoverflow.com/questions/28317607
复制相似问题