2016-04-28 104 views
0

我想限制SDImageCache的內存緩存和磁盤緩存的大小。 以下是我用於下載圖像的代碼。默認情況下,它將圖像保存在緩存中,並存在於沙盒的Library文件夾中。如何限制SDImageCache的磁盤和內存緩存的大小

我的應用 ID /圖書館/緩存/ com.hackemist.SDWebImageCache.default/

#import <SDWebImage/UIImageView+WebCache.h> 

... 

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
     static NSString *MyIdentifier = @"MyIdentifier"; 

     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier]; 
     if (cell == nil) { 
      cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault 
              reuseIdentifier:MyIdentifier] autorelease]; 
     } 

     // Here we use the new provided sd_setImageWithURL: method to load the web image 
     [cell.imageView sd_setImageWithURL:[NSURL URLWithString:@"http://www.domain.com/path/to/image.jpg"] 
          placeholderImage:[UIImage imageNamed:@"placeholder.png"]]; 

     cell.textLabel.text = @"My Text"; 
     return cell; 
    } 

回答

0

如果你正在尋找限制高速緩存的最大大小,你可以做手工在SDImageCache.m並將maxCacheSize設置爲有限的字節數。您可以使用
static const NSInteger kDefaultCacheMaxCacheAge = 60 * 60 * 24 * 7; // 1 week
查看緩存時間如何到一週,並對緩存大小執行相同的操作。

+0

是否有任何其他的方法? – Burak

1

目標C

// Setting disk cache  
[[[SDImageCache sharedImageCache] config] setMaxCacheSize:1000000 * 20]; // 20 MB 

// Setting memory cache 
[[SDImageCache sharedImageCache] setMaxMemoryCost:15 * 1024 * 1024]; // aprox 15 images (1024 x 1024) 

夫特4

// Setting disk cache 
SDImageCache.shared().config.maxCacheSize = 1000000 * 20 // 20 MB 

// Setting memory cache 
SDImageCache.shared().maxMemoryCost = 15 * 1024 * 1024