一
@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