2016-04-28 6 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
を使用してキャッシュの経過時間が1週間にどのようになっているかを見て、キャッシュのサイズを同じにすることができます。

+0

他の方法はありますか? – Burak

1

のObjective-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 
関連する問題