如何在iOS中缓存数据 [英] How to cache data in ios

查看:112
本文介绍了如何在iOS中缓存数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从服务器加载了XML数据(包括图像,文本等),并在iPhone屏幕上显示了这些数据。

I loaded XML data (including images, text,...) from server and display that data on iphone screen.

如何缓存数据以重新当我其他时间访问该屏幕时,加载该屏幕。会更快。 (不需要再次重新加载XML数据)?

How can i cache data to re-load that screen when i visit that screen other time. It will be faster . (dont need re-load XML data again)?

谢谢。

推荐答案

使用 EGOcache API。
只需将EGOCache.h文件导入您的类中

Use EGOcache API. Just import the EGOCache.h file in your class

- (void)setObject:(id<NSCoding>)anObject forKey:(NSString*)key;
-(void)setObject:(id)anObject forKey:(NSString*)key withTimeoutInterval:(NSTimeInterval)timeoutInterval;
-(id)objectForKey:(NSString*)key;

使用第一种方法通过forkey设置数据。
如果您想确定缓存时间,请使用第二种方法。

Use the first method for set your data with a forkey. If you want secify the cache time then use the second method.

编辑

EGOCache将永久保存您的数据,请参见此处使用NSCache,其中包含各种自动删除策略。

EGOCache will save your data permanently, See here to for usage of NSCache which is incorporates various auto-removal policies.

这篇关于如何在iOS中缓存数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆