https://github.com/soffes/SAMCache
Fancy caching with on-disk persistence
https://github.com/soffes/SAMCache
Last synced: 11 days ago
JSON representation
Fancy caching with on-disk persistence
- Host: GitHub
- URL: https://github.com/soffes/SAMCache
- Owner: soffes
- License: mit
- Archived: true
- Fork: true (Synthetic/SYCache)
- Created: 2012-05-04T16:52:55.000Z (almost 13 years ago)
- Default Branch: master
- Last Pushed: 2015-09-08T02:53:10.000Z (over 9 years ago)
- Last Synced: 2025-04-04T03:46:16.194Z (12 days ago)
- Language: Objective-C
- Homepage:
- Size: 334 KB
- Stars: 194
- Watchers: 3
- Forks: 19
- Open Issues: 5
-
Metadata Files:
- Readme: Readme.markdown
- License: LICENSE
Awesome Lists containing this project
- awesome - SAMCache - Fancy caching with on-disk persistence (etc)
- awesome - SAMCache - Fancy caching with on-disk persistence (etc)
README
# SAMCache
[](https://github.com/Carthage/Carthage)
Simple in memory and on disk cache. It's backed by an [NSCache](https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/NSCache_Class/Reference/Reference.html) in memory, so it automatically purges itself when memory gets low. Purged memory keys will automatically be loaded from disk the next time the are requested.
## Usage
The API is simple.
``` objective-c
- (id)objectForKey:(NSString *)key;
- (void)objectForKey:(NSString *)key usingBlock:(void (^)(id object))block;
- (void)setObject:(id )object forKey:(NSString *)key;
```You can also use subscripts:
``` objective-c
SAMCache *cache = [SAMCache sharedCache];
cache[@"answer"] = @42;
NSLog(@"The answer is %@", cache[@"answer"]);
```See [SAMCache.h](SAMCache/SAMCache.h) for the full list of methods.
## Adding to Your Project
Simply add `SAMCache.h` and `SAMCache.m` to your project or if you're using CocoaPods, simply add 'SAMCache' to your Podfile.