Skip to content

Support caching images balancing between I/O and memory with LRU algorithm

License

Notifications You must be signed in to change notification settings

hmchuong/iOS-ObjectiveC-HMCImageCache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

HMCImageCache

Build Status Version License Platform

Component Libraries

HMCThreadSafeMutableCollection provides thread safe array and dictionary
HMCDownloadManager provides APIs for downloading image from URL

Requirements

  • iOS 8.0+
  • Xcode 8.3+

Features

  • Caching image on disk
  • Caching image on memory
  • Balancing I/O read write and memory usage
  • Auto adjusting memory usage based on avaiable memory (5% of available mem in background, 80% of available mem in foreground)
  • Release memory by LRU algorithm
  • Auto remove unsued cache files on disk after 30 days
  • Get image from url with target size
  • Set UIImageView with image from URL
  • Set UIButton with image from URL

Installation

HMCImageCache is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'HMCImageCache'

Usage

Singleton object

To get image caching instance:

HMCImageCache *imageCache = [HMCImageCache sharedInstance];

To store image to cache

UIImage *image = ...;
NSString *identifier = ...;
[imageCache storeImage:image withKey:identifier];

To get origin image from cache

image = [imageCache imageFromKey:identifier storeToMem:YES];  // storeToMem: do you want image store to memory

To get image with target size

CGSize size = CGSizeMake(300,400); // Image with size 300px x 400 px
image = [imageCache imageFromKey:identifier withSize:size];

To get image from URL

[imageCache imageFromURL:url
          withTargetSize:CGSizeMake(300,400)
              completion:^(UIImage *image){
                  // do something with image
              }
           callbackQueue:dispatch_get_main_queue()];

To set image to UIImageView from URL

NSURL *url;
UIImageView *imageView;
[imageView HMCSetImageFromURL:url forState: UIControlStateNormal];

To set image to UIButton from URL

NSURL *url;
UIButton *button;
[button HMCSetImageFromURL:url forState: UIControlStateNormal];

To remove an image from cache

[imageCache removeImageForKey:identifier];

To remove all images from cache

[imageCache removeAllCache];

Author

chuonghuynh, minhchuong.itus@gmail.com

License

HMCImageCache is available under the MIT license. See the LICENSE file for more info.

About

Support caching images balancing between I/O and memory with LRU algorithm

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published