Skip to content

Repository files navigation

BRCacheManager

CI StatusVersionLicensePlatform

A simple, efficient, disk based cache for your models. Typically you might fetch some content via AFNetwroking, convert JSON to your custom model and display it. Speed up your app by using BRCacheManager to cache your content for x amount of seconds. Cached content expiration and clean up is managed for you out of the box.

Usage

(coming soon) To run the example project, clone the repo, and run pod install from the Example directory first.

Example

Example of workflow with AFNetworking.

#import<BRCacheManager.h>
+ (void)getMyContent
completionHandler:(CustomBlock)completionHandler
{
NSString *path = @"myendpoint";
//check if we have content in the cache with a max age of 5 minutesid contents = [[BRCacheManager sharedManager] getCachedContentForKey:path withExpireTimeInSeconds:(60 * 5)];
if (contents) {
returncompletionHandler(contents, nil);
}
[[CustomSessionManager sharedClient] GET:path
parameters:nilsuccess:^(NSURLSessionDataTask *task, id responseObject)
{
MyModel *myModel = [selfcustomModelFromJson:responseObject];
//save your content to disk
[[BRCacheManager sharedManager] saveCachedContent:[myModel copy] forKey:path];
returncompletionHandler(myModel, nil);
} failure:^(NSURLSessionDataTask *task, NSError *error) {
returncompletionHandler(nil, error);
}];
}

Requirements

iOS 7 + ARC. If you're caching a custom model, it must implement NSCoding.

Installation

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

pod "BRCacheManager"

Contributors

A special thanks to those who have contributed. Please submit all pull requests against the development branch.

Michael Mork - https://github.com/Morkrom

License

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

About

A simple, efficient, disk based cache for your models. Cached content expiration and clean up is managed for you out of the box.

Resources

Stars

5 stars

Watchers

3 watching

Forks

Releases

Packages

Contributors

Languages