1

I am using SDwebimage Framework for caching images, so downloading number of images increases daily, so after 3-4 days of using application, causes increasing cache,which causes application performance degrading, is there anyway to improve performance

user1330379
  • 15
  • 1
  • 6

2 Answers2

0

Take a look at this SO post here

You can set the period for how long the cache will last, and then it will be flushed. Also in addition, you can play around with the maxCacheSize value in SDImageCache.m in the 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;
                }
            }
        }
    }
Community
  • 1
  • 1
AshesToAshes
  • 937
  • 3
  • 14
  • 31
0

You can simply set a global cache value for your shared instance of SDImageCache.

Just call the following on your AppDelegate:

// limit SDImage cache to 50 MGB

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

Mert Kahraman
  • 445
  • 6
  • 10
  • I'm not an ios developer, I need to configure my cache for react native in my app delegate. What's the import statement and which callback would I put it in the app delegate? – evanjmg Dec 26 '18 at 23:31