Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/soffes/SAMCache
Fancy caching with on-disk persistence
https://github.com/soffes/SAMCache
Last synced: about 1 month 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 (over 12 years ago)
- Default Branch: master
- Last Pushed: 2015-09-08T02:53:10.000Z (over 9 years ago)
- Last Synced: 2024-10-30T15:55:31.601Z (about 1 month ago)
- Language: Objective-C
- Homepage:
- Size: 334 KB
- Stars: 195
- 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
[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](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.