A Cache Library with flexible storage options and policies
This is a practice project for beginner.
Copy /scr folder to your project and import "MMCache.h".
- Custom object must conform to NSCoding. Extend your existing class with category and adapt NSCoding.
- Instantiate MMCache instance (singleton sharedCache is available).
- Configure cache policy (LRU, LFU, FIFO, etc.), storage type (in memory or persistent), and cache capacity (in terms of number of cached items)
- Add/remove/achieve object using provided methods.
Example
MMCache.sharedCache.policyType = MMCPolicyTypeLRU;
MMCache.sharedCache.storageType = MMCStorageTypeInMemory;
MMCache.sharedCache.capacity = 100;
NSArray <NSString *> *names = @[@"Ana, Elsa, Lisa, Christ"];
[MMCache.sharedCache saveObject:names level:MMCLevelHigh];
NSDictionary <NSString *, NSNumber *> *kids = @{@"Alex" : @5, @"Phil" : @2, @"Mark" : @10};
[MMCache.sharedCache saveObject:kids level:MMCLevelLow];
- Persistent type of storage is not implemented yet. This class must conforms to protocol 'MMCStorable'.
- Dynamically setting capacity should trim cache size to desired value using given policy.
- Storage should provide more flexible query methods other than what is defined in 'MMCStorable'.