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.
(coming soon)
To run the example project, clone the repo, and run pod install
from the Example directory first.
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 minutes
id contents = [[BRCacheManager sharedManager] getCachedContentForKey:path withExpireTimeInSeconds:(60 * 5)];
if (contents) {
return completionHandler(contents, nil);
}
[[CustomSessionManager sharedClient] GET:path
parameters:nil
success:^(NSURLSessionDataTask *task, id responseObject)
{
MyModel *myModel = [self customModelFromJson:responseObject];
//save your content to disk
[[BRCacheManager sharedManager] saveCachedContent:[myModel copy] forKey:path];
return completionHandler(myModel, nil);
} failure:^(NSURLSessionDataTask *task, NSError *error) {
return completionHandler(nil, error);
}];
}
iOS 7 + ARC. If you're caching a custom model, it must implement NSCoding.
BRCacheManager is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "BRCacheManager"
A special thanks to those who have contributed. Please submit all pull requests against the development branch.
Michael Mork - https://github.com/Morkrom
BRCacheManager is available under the MIT license. See the LICENSE file for more info.