Sdwebimage: How can I set the time for that my cache will stored?

Created on 9 Jun 2014  路  7Comments  路  Source: SDWebImage/SDWebImage

Most helpful comment

I think that the change of the constant value is a bad idea. Maybe it is better like this?
[SDImageCache sharedImageCache].config.maxCacheAge = 60 * 60 * 24;

All 7 comments

Hello @bizibizi
you can set the max cache age in the SDImageCache.m file.
you can change the kDefaultCacheMaxCacheAge to meet your needs

thanks

thanks

Closing issue based on @mythodeia's response. Thanks @mythodeia

I think that the change of the constant value is a bad idea. Maybe it is better like this?
[SDImageCache sharedImageCache].config.maxCacheAge = 60 * 60 * 24;

@RunesReader I'm getting

maxCacheAge cannot be found in forward class of SDImageCacheConfig

error in 4.0.0 beta. How can I set that?

@burakkilic
For 4.0.0

//
//  AppDelegate.m
//  SDWebImageTest
//
//  Created by Igor Arsenkin on 12.11.16.
//  Copyright 漏 2016 Igor Arsenkin. All rights reserved.
//

#import "AppDelegate.h"

#import "ARRStartViewController.h"
#import "SDImageCacheConfig.h"
#import "SDImageCache.h"

static const NSInteger kARRMaxCacheAge = 60 * 60 * 24; // 1 day

#pragma mark -
#pragma mark <UIApplicationDelegate>

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    [self setupSDWebImageCache];

    self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
    UIWindow *window = self.window;

    window.rootViewController = [ARRStartViewController controllerWithCharacters:nil];
    [window makeKeyAndVisible];

    return YES;
}

#pragma mark -
#pragma mark Private

- (void)setupSDWebImageCache {
    [SDImageCache sharedImageCache].config.maxCacheAge = kARRMaxCacheAge;
}

@end

This is work fine for me.

For 3.8.2

- (void)setupSDWebImageCache {
    [[SDImageCache sharedImageCache] setMaxCacheAge:kARRMaxCacheAge];
}
Was this page helpful?
0 / 5 - 0 ratings