1
이미지를 캐싱하기 위해 SDwebimage Framework를 사용하고 있으므로 이미지를 다운로드하는 횟수가 매일 증가하므로 3-4 일 후에 애플리케이션 성능이 저하되어 애플리케이션 성능이 저하됩니다. 성능sdwebimage 캐시가 최대 크기에 도달
이미지를 캐싱하기 위해 SDwebimage Framework를 사용하고 있으므로 이미지를 다운로드하는 횟수가 매일 증가하므로 3-4 일 후에 애플리케이션 성능이 저하되어 애플리케이션 성능이 저하됩니다. 성능sdwebimage 캐시가 최대 크기에 도달
는 SO here
당신은 캐시가 지속될 얼마 동안의 기간을 설정할 수 있습니다 게시물이 한 번 봐, 그리고 다음은 플러시됩니다. 또한 cleanDiskWithCompletionBlock의 SDImageCache.m에서 maxCacheSize 값으로 재생할 수 있습니다.
// 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;
}
}
}
}
감사합니다. 재에 대한 @ashes가 – user1330379
어떻게 위 코드 블록에서 20MB와 같은 최대 제한을 설정하는지 @AshesToAshes –