Skip to content
This repository has been archived by the owner on Apr 5, 2021. It is now read-only.

Latest commit

 

History

History
50 lines (36 loc) · 992 Bytes

README.md

File metadata and controls

50 lines (36 loc) · 992 Bytes

ECDataCache

A generic NSData cache for storing data to disk, which is backed by NSCache for in-memory data.

Usage

Just include the header somewhere up top:

#import "ECDataCache.h"

Then use it in your code like so:

NSData *someData = [ECDataCache.sharedCache dataForKey:@"some key"];
if (someData) {
    // Do stuff with someData
} else {
    // someData doesn't exist
}

You can also use it with URLs to store and load images. For example:

NSURL *url = [NSURL URLWithString:@"http://www.educreations.com/static/images/logo/logo-large-dark.png"];
NSData *data = [ECDataCache.sharedCache dataForURL:url];
if (data) {
    // We are good to go
    UIImage *image = [UIImage imageWithData:data];
} else {
    // Fetch the url
    ...

    // On successful fetch, store the image to disk
    [ECDataCache.sharedCache setData:data forURL:url];
}

License

Uses the MIT license.