iOS原生数据存储策略
一
@interface NSCache : NSObject
Description
A mutable collection you use to temporarily store transient key-value pairs that are subject to eviction when resources are low.
Cache objects differ from other mutable collections in a few ways:
- The NSCache class incorporates various auto-eviction policies, which ensure that a cache doesn’t use too much of the system’s memory. If memory is needed by other applications, these policies remove some items from the cache, minimizing its memory footprint.
- You can add, remove, and query items in the cache from different threads without having to lock the cache yourself.
- Unlike an NSMutableDictionary object, a cache does not copy the key objects that are put into it.
You typically use NSCache objects to temporarily store objects with transient data that are expensive to create. Reusing these objects can provide performance benefits, because their values do not have to be recalculated. However, the objects are not critical to the application and can be discarded if memory is tight. If discarded, their values will have to be recomputed again when needed.
Objects that have subcomponents that can be discarded when not being used can adopt the NSDiscardableContent protocol to improve cache eviction behavior. By default, NSDiscardableContent objects in a cache are automatically removed if their content is discarded, although this automatic removal policy can be changed. If an NSDiscardableContent object is put into the cache, the cache calls discardContentIfPossible on it upon its removal.
只是内存存储,要与文件存储系统联合使用。
参考SDImage;
二
@interface NSURLCache : NSObject
Description
An object that maps URL requests to cached response objects.
The NSURLCache class implements the caching of responses to URL load requests by mapping NSURLRequest objects to NSCachedURLResponse objects. It provides a composite in-memory and on-disk cache, and lets you manipulate the sizes of both the in-memory and on-disk portions. You can also control the path where cache data is stored persistently.
Note
In iOS, the on-disk cache may be purged when the system runs low on disk space, but only when your app is not running.
文件与内存双重存储;存储策略为网络数据缓存策略。缓存的路径(首次引用NSURLCache会创建以下文件):
查看方式:cat命令。
问题:request会在处理过程成发生变化。
三
@interface NSUserDefaults : NSObject |
|
Description |
An interface to the user’s defaults database, where you store key-value pairs persistently across launches of your app. The At runtime, you use |
---|
存储方式为本质存储;
路径:
四
NSKeyedArchiver
NSCoding (NSKeyedArchiver\NSKeyedUnarchiver) (能把任何对象都直接保存成文件的方式)
- (BOOL)writeToFile:(NSString *)path atomically:(BOOL)useAuxiliaryFile; |
|
Description |
Writes the data object's bytes to the file specified by a given path. This method may not be appropriate when writing to publicly accessible files. To securely write data to a public location, use NSFileHandle instead. For more information, seeSecuring File Operations in Secure Coding Guide. |
---|
五
coredata
最新文章
- 高性能JavaScript 加载和执行
- 自制公众平台Web Api(微信)
- ajax contenttype
- 《Apache服务之php/perl/cgi语言的支持》RHEL6——服务的优先级
- javascript GB2312转UTF8
- 类库探源——System.Delegate
- 两种动态载入修改后的python模块的方法
- 完成端口(Completion Port)详解(超级长,超级清楚)
- JAVA中字符串函数subString的用法小结
- YII 1.0模型标签与验证规则,前后台验证
- let内嵌lambda使用set!构成闭包
- C语言可变参数
- 集腋成裘-09-ECharts -HelloECharts-02
- ArcGIS为面要素生成邻接矩阵
- Google Analytics电子商务篇(Universal版)
- react 中子组件调用父组件的方法
- MDK-ARM输出HEX文件重命名设置
- mysql学习(2)-Navicat Premium 12 链接MySQL8.0.11数据库报2059错误
- MVC教程六:视图的寻址
- SharePoint自动化系列——通过PowerShell创建SharePoint Web