美文网首页
NSCache的用法

NSCache的用法

作者: 木兮_君兮 | 来源:发表于2018-01-04 13:53 被阅读14次

是什么

NSCache 是一个类似NSDictionary的工具,当内存警告的时候,他会自动释放。

-源码

@interface NSCache <KeyType, ObjectType> : NSObject {
@private
    id _delegate;
    void *_private[5];
    void *_reserved;
}

@property (copy) NSString *name;

@property (nullable, assign) id<NSCacheDelegate> delegate;

- (nullable ObjectType)objectForKey:(KeyType)key;
- (void)setObject:(ObjectType)obj forKey:(KeyType)key; // 0 cost
- (void)setObject:(ObjectType)obj forKey:(KeyType)key cost:(NSUInteger)g;
- (void)removeObjectForKey:(KeyType)key;

- (void)removeAllObjects;

@property NSUInteger totalCostLimit;    // limits are imprecise/not strict
@property NSUInteger countLimit;    // limits are imprecise/not strict
@property BOOL evictsObjectsWithDiscardedContent;

@end

@protocol NSCacheDelegate <NSObject>
@optional
- (void)cache:(NSCache *)cache willEvictObject:(id)obj;
@end

做什么

拿来可以做性能优化,可以做缓存,搭配本地数据库,在恰当的时候对数据做恰当的处理。

怎么做

1. 初始化 (NSCache)
2. 数据操作:- setObject:forKey: (写)
           - objectForKey:(读) 

相关文章

  • 系统框架--50:构建缓存时选用NSCache

    NSCache NSCache是苹果官方提供的缓存类,用法与NSMutableDictionary的用法很相似,在...

  • 52个有效方法(50) - 构建缓存时,选用NSCache而非N

    NSCache NSCache是苹果官方提供的缓存类,用法与NSMutableDictionary的用法很相似,在...

  • 缓存-YYCache

    参考文档 NSCache NSCache 与 NSMutableDictionary 用法相似,但是线程安全的,不...

  • NSCache

    NSCache NSCache是苹果官方提供的缓存类,它的用法和NSMutableDictionary非常类似. ...

  • 谈一谈NSCache

    NSCache介绍 NSCache是苹果提供的一套缓存机制,与NSMutableDictionary可变字典的用法...

  • NSCache深入理解

    NSCache是什么东东? NSCache是苹果提供的一套缓存机制,用法和NSMutableDictionary类...

  • NSCache

    NSCache 专门用来做缓存处理的 objectForKey(和字典用法很像) 简介 NSCache是苹果官方提...

  • iOS系统中缓存的使用

    原文发布于:wenghengcong.com NSCache NSCache是系统提供的缓存类,用法类似于NSMu...

  • NSCache的用法

    是什么 NSCache 是一个类似NSDictionary的工具,当内存警告的时候,他会自动释放。 -源码 做什么...

  • NSCache理解及应用

    首先NSCache是苹果官方提供的缓存类,它的用法与NSMutableDictionary的用法很相似。 NSCa...

网友评论

      本文标题:NSCache的用法

      本文链接:https://www.haomeiwen.com/subject/qtdrnxtx.html