Question: I want to limit the size of memory cache and disk cache for SDImageCache.
Below is the code I have used for downloading the images. By default it saves the images in the cache and it is present In the sandbox's Library folder. 

> 
> my Application
>  ID/Library/Caches/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;
    }

```

Answer: 
**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)

```

**Swift 4** 

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

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

```
If you're looking to limit the maximum size of the cache, you can manually do that in **SDImageCache.m** and set `maxCacheSize` to a limited number of bytes. You can take a look at how the cache age is being to one week using   
 `static const NSInteger kDefaultCacheMaxCacheAge = 60 * 60 * 24 * 7; // 1 week`  

and do the same for the cache size.