我在我的应用中使用ASIHttpRequest库,我试图为特定请求设置缓存,以便它可以在一段时间内使用(if没有数据可以从服务器或没有互联网连接),除此之外它会拒绝/删除缓存,所以不会使用它。ASIHttpRequest - 在特定时间间隔后删除缓存
所以我试图得到的请求是,首先检查它是否可以在线检索数据,如果它无法访问它(无论出于何种原因,服务器关闭或没有Internet连接可用),然后使用缓存,只要它没有过期。我希望设置一定的时间,比如12小时之后将数据保存到缓存中。
我试过到目前为止是:
// Set secondsToCache on the request to override any expiry date for the content set by the server, and store
// this response in the cache until secondsToCache seconds have elapsed
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setSecondsToCache:60*60*24*30]; // Cache for 30 days
这是从网站上的示例获取的。
但是,如上所述,这似乎没有我想要的效果。
如何将数据缓存一段时间,之后将其从缓存中删除?
你会看到什么发生? – JosephH
没有效果 - 我用2分钟的时间间隔测试了它,所以我将setSecondsToCache中的秒数设置为60 * 2,并等待3分钟,并且当我将iPhone设置为飞行模式时仍然使用缓存的数据。所以它似乎没有任何影响。 – SMSidat
你在请求上设置了什么cachePolicy? – JosephH