dondreytaylor / ECDataCache

A generic NSData cache backed by NSCache for in-memory data.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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.

About

A generic NSData cache backed by NSCache for in-memory data.

License:MIT License


Languages

Language:Objective-C 90.2%Language:Ruby 9.8%