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
iOS原生数据存储策略的更多相关文章
- IOS开发数据存储篇—IOS中的几种数据存储方式
IOS开发数据存储篇—IOS中的几种数据存储方式 发表于2016/4/5 21:02:09 421人阅读 分类: 数据存储 在项目开发当中,我们经常会对一些数据进行本地缓存处理.离线缓存的数据一般都 ...
- iOS 应用数据存储方式(XML属性列表-plist)
iOS 应用数据存储方式(XML属性列表-plist) 一.ios应用常用的数据存储方式 1.plist(XML属性列表归档) 2.偏好设置 3.NSKeydeArchiver归档(存储自定义对象) ...
- iOS开发UI篇—ios应用数据存储方式(XML属性列表-plist)
iOS开发UI篇—ios应用数据存储方式(XML属性列表-plist) 一.ios应用常用的数据存储方式 1.plist(XML属性列表归档) 2.偏好设置 3.NSKeydeArchiver归档(存 ...
- iOS开发UI篇—ios应用数据存储方式(偏好设置)
iOS开发UI篇—ios应用数据存储方式(偏好设置) 一.简单介绍 很多iOS应用都支持偏好设置,比如保存用户名.密码.字体大小等设置,iOS提供了一套标准的解决方案来为应用加入偏好设置功能 每个应用 ...
- iOS开发UI篇—ios应用数据存储方式(归档)
iOS开发UI篇—ios应用数据存储方式(归档) 一.简单说明 在使用plist进行数据存储和读取,只适用于系统自带的一些常用类型才能用,且必须先获取路径相对麻烦: 偏好设置(将所有的东西都保存在同 ...
- iOS本地数据存储(转载)
看到一篇不错的文章,推荐给大家!!! 应用沙盒 1)每个iOS应用都有自己的应用沙盒(应用沙盒就是文件系统目录),与其他文件系统隔离.应用必须待在自己的沙盒里,其他应用不能访问该沙盒 2)应用沙盒的文 ...
- iOS应用数据存储的常用方式
iOS应用 数据存储的常用方式 XML属性列表 plist Preference 偏好设置 NSKeyedArchiver 归档 Core Data SQLite3 应用沙盒: Layer: ...
- iOS开发技术分享(1)— iOS本地数据存储
iOS开发技术分享(1)— iOS本地数据存储 前言: 我本是一名asp.net程序员,后来加入了iOS游戏开发队伍,到现在也有一年多的时间了.这一年来,每天都干到2.3点钟才睡觉,不为别的,只为了学 ...
- iOS开发UI篇—ios应用数据存储方式(归档) :转发
本文转发至:文顶顶http://www.cnblogs.com/wendingding/p/3775293.html iOS开发UI篇—ios应用数据存储方式(归档) 一.简单说明 在使用plist ...
随机推荐
- iPhone Mach-O文件格式与代码签名
错误现象1) 直接运行/Applications/MobileFonex.app/MobileFonexKilled: 9 2)gdb调试Program received signal EXC_BAD ...
- js 或运算
表达式a && 表达式b : 计算表达式a(也可以是函数)的运算结果, 如果为 True, 执行表达式b(或函数),并返回b的结果: 如果为 False,返回a的结果: 表达式a || ...
- MVC传值前台
ViewBag.model = bLL.GetModel((int)id); ViewBag.RecruitmentTime = ViewBag.model.RecruitmentTime.ToStr ...
- Kattis -Safe Passage(撑伞问题)
Safe Passage Photo by Ian Burt A group of friends snuck away from their school campus, but now they ...
- JS 用+1、-1填12()34()56()78()9=59
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- java中String和int的互相转化
1. String 转 int 方式1:Integer.parseInt(); 方式2: Integer.valueOf(myStr).intValue(); 2. int 转String 方式1: ...
- 【UOJ139】【UER #4】被删除的黑白树
题意: 很久很久以前,有一棵树加入了 UOJ 群. 这天,在它讨论“一棵树应该怎么旋转”的时候一不小心被删除了,变成了被删除的树. 突然间,它突然发现它失去了颜色,变成了一棵纯白的树.这让它感觉很焦躁 ...
- [BZOJ1999] 树网的核 [数据加强版] (树的直径)
传送门 如果只是想验证算法正确性这里是洛谷数据未加强版 Description 设T=(V, E, W) 是一个无圈且连通的无向图(也称为无根树),每条边带有正整数的权,我们称T为树网(treenet ...
- CentOS6.8安装
VMware下CentOS 6.8安装配置 简述 Linux的安装方法有很多种,下面,我们主要以镜像安装为例,介绍CentOS的安装过程及相关的参数设置,详细步骤如下. CentOS安装配置 ...
- CSS中选择器优先级的权重计算
CSS中选择器优先级的权重计算 先看一段代码,如下: a{ color: red; } #box a{ color: green; } [class="box"] a{ color ...