pod search EGOCache
pod 'EGOCache', '~> 2.1.3'
pod install
让数组中的对象遵循NSCodeing协议即可。
EGOCache常用方法如下:
// 创建缓存目录
- (id)initWithCacheDirectory:(NSString*)cacheDirectory;
// 清除缓存
- (void)clearCache;
// 清除对应key 的缓存
- (void)removeCacheForKey:(NSString*)key;
// 判读是否有该key
- (BOOL)hasCacheForKey:(NSString*)key;
// 默认缓存保留一天
@property(nonatomic,assign) NSTimeInterval defaultTimeoutInterval; // Default is 1 day
// 可自定义缓存保留日期
- (void)setData:(NSData*)data forKey:(NSString*)key withTimeoutInterval:(NSTimeInterval)timeoutInterval;
// 缓存字符串
-(void)cacheString
{
NSString *saveString= @"我的名字是Allen";
[[EGOCache globalCache]setString:saveString forKey:@"string"];
NSString *cacheString = [[EGOCache globalCache]stringForKey:@"string"];
NSLog(@"string===%@",cacheString);
}
//缓存数组
-(void)cacheArray
{
NSArray *saveArray = @[@"1",@"2",@"3"];
[[EGOCache globalCache]setObject:saveArray forKey:@"array"];
NSArray *cacheArray = (NSArray *) [[EGOCache globalCache]objectForKey:@"array"];
NSLog(@"array==%@",cacheArray);
}
// 缓存data
-(void)cacheData
{
NSString *saveString= @"我的名字是Allen";
NSData *data = [saveString dataUsingEncoding: NSUTF8StringEncoding];
[[EGOCache globalCache]setData:data forKey:@"data"];
NSData *cacheData = [[EGOCache globalCache]dataForKey:@"data"];
NSLog(@"data==%@",cacheData);
}
// 缓存图片
- (void)setImage:(UIImage*)anImage forKey:(NSString*)key;