https://github.com/hmchuong/ios-objectivec-hmcimagecache
Support caching images balancing between I/O and memory with LRU algorithm
https://github.com/hmchuong/ios-objectivec-hmcimagecache
cocoapods imagecache ios objective-c xcode
Last synced: about 2 months ago
JSON representation
Support caching images balancing between I/O and memory with LRU algorithm
- Host: GitHub
- URL: https://github.com/hmchuong/ios-objectivec-hmcimagecache
- Owner: hmchuong
- License: mit
- Created: 2017-10-16T03:02:09.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-03-31T08:46:16.000Z (about 7 years ago)
- Last Synced: 2025-04-05T09:18:17.105Z (about 2 months ago)
- Topics: cocoapods, imagecache, ios, objective-c, xcode
- Language: Objective-C
- Size: 199 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# HMCImageCache
[](https://travis-ci.org/hmchuong/iOS-ObjectiveC-HMCImageCache)
[](http://cocoapods.org/pods/HMCImageCache)
[](http://cocoapods.org/pods/HMCImageCache)
[](http://cocoapods.org/pods/HMCImageCache)## Component Libraries
[HMCThreadSafeMutableCollection](http://cocoapods.org/pods/HMCThreadSafeMutableCollection) provides thread safe array and dictionary
[HMCDownloadManager](http://cocoapods.org/pods/HMCDownloadManager) provides APIs for downloading image from URL
## Requirements
- iOS 8.0+
- Xcode 8.3+## Features
- [x] Caching image on disk
- [x] Caching image on memory
- [x] Balancing I/O read write and memory usage
- [x] Auto adjusting memory usage based on avaiable memory *(5% of available mem in background, 80% of available mem in foreground)*
- [x] Release memory by LRU algorithm
- [x] Auto remove unsued cache files on disk after 30 days
- [x] Get image from url with target size
- [x] Set UIImageView with image from URL
- [x] Set UIButton with image from URL## Installation
HMCImageCache is available through [CocoaPods](http://cocoapods.org). To install
it, simply add the following line to your Podfile:```ruby
pod 'HMCImageCache'
```
## Usage### Singleton object
To get image caching instance:
```ObjectiveC
HMCImageCache *imageCache = [HMCImageCache sharedInstance];
```### To store image to cache
```ObjectiveC
UIImage *image = ...;
NSString *identifier = ...;
[imageCache storeImage:image withKey:identifier];
```### To get origin image from cache
```ObjectiveC
image = [imageCache imageFromKey:identifier storeToMem:YES]; // storeToMem: do you want image store to memory
```### To get image with target size
```ObjectiveC
CGSize size = CGSizeMake(300,400); // Image with size 300px x 400 px
image = [imageCache imageFromKey:identifier withSize:size];
```### To get image from URL
```ObjectiveC
[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
```ObjectiveC
NSURL *url;
UIImageView *imageView;
[imageView HMCSetImageFromURL:url forState: UIControlStateNormal];
```### To set image to UIButton from URL
```ObjectiveC
NSURL *url;
UIButton *button;
[button HMCSetImageFromURL:url forState: UIControlStateNormal];
```### To remove an image from cache
```ObjectiveC
[imageCache removeImageForKey:identifier];
```### To remove all images from cache
```ObjectiveC
[imageCache removeAllCache];
```## Author
chuonghuynh, [email protected]
## License
HMCImageCache is available under the MIT license. See the LICENSE file for more info.