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

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

License

Notifications You must be signed in to change notification settings

educreations/ECDataCache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

Resources

License

Stars

Watchers

Forks

Packages

No packages published