首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >size映像缓存达到最大大小。

size映像缓存达到最大大小。
EN

Stack Overflow用户
提问于 2015-02-04 09:18:01
回答 2查看 3.6K关注 0票数 1

我使用SDwebimage框架来缓存图像,所以下载图像的数量每天都在增加,所以在使用应用程序3-4天后,缓存会增加,从而导致应用程序性能下降,是否存在提高性能的问题?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-06-28 06:27:17

看看这个,所以发布here

您可以设置缓存持续时间的时间段,然后刷新缓存。此外,您还可以在maxCacheSize中使用SDImageCache.m中的cleanDiskWithCompletionBlock值。

代码语言:javascript
复制
    // 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;
                }
            }
        }
    }
票数 0
EN

Stack Overflow用户

发布于 2018-05-30 13:56:20

您可以简单地为共享的SDImageCache实例设置一个全局缓存值。

只需在AppDelegate上调用以下命令:

// limit SDImage cache to 50 MGB

SDImageCache.shared().config.maxCacheSize = 1_000_000 * 50

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28317607

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档