Skip to content

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

License

Notifications You must be signed in to change notification settings

lostincode/BRCacheManager

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

BRCacheManager

CI Status Version License Platform

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 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);
     }];
}

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

License

Stars

Watchers

Forks

Packages

No packages published