TMCache设计的目的是用于存储临时持久化对象的开源iOS/OS key/value缓存类库,减少重复创建像下载数据、缓慢的处理结果这样的昂贵性能花销。TMCache由两个本身相似的存储组成,一个是TMMemoryCache,存在于内存中,另外一个是TMDiskCache,存在于硬盘中,它们都支持GCD和从多线程中读取数据。在iOS中,如果使用内存缓存(TMMemoryCache),当App收到内存使用警告或者App被移到后台时(也就是打开了其他App),TMCache 会自动清理内存里面的缓存数据。当使用硬盘缓存(TMDiskCache)时, 需要开发者手动去清理缓存或者事先设置缓存区容量或者缓存期限。
Github托管地址:https://github.com/tumblr/TMCache
#import "TMCache.h" @interface TMCache (Extension) + (instancetype)TemporaryCache; + (instancetype)PermanentCache; @end #import "TMCacheExtend.h" #define kTemporaryCache @"com.dv.cache.temporary" #define kPermanentCache @"com.dv.cache.permanentCache" @implementation TMCache (Extension) + (instancetype)TemporaryCache{ return [[TMCache sharedCache] initWithName:kTemporaryCache]; } + (instancetype)PermanentCache { return [[TMCache sharedCache] initWithName:kPermanentCache]; }
调用方法
[[TMCache TemporaryCache] setObject:history forKey:kSearchHistory];
浙公网安备 33010602011771号