开发者

Appcelerator caching techniques. Feedback wanted!

Titanium SDK version: 1.6.1 iPhone SDK version: 4.2

I am开发者_开发知识库 trying to build a solution to cache JSON calls. I have done a first attempt that does the job, but is there a better solution? I am using textfiles to save the JSON output, is this OK performance wise?

http://pastie.org/1734763

Thankful for all feedback!


I think that'd be ok. As long as the files aren't massive in number/size it should perform quite well.

The other approach you could try if you decide you're not happy with performance, or want to maintain less code, is to use App storage, which persists data beyond app sessions.

Titanium.App.setString('jsonResponse', this.responseText);
Titanium.App.setInt('expires', this.responseText.expires);

Then before you make your request you can check if the cache is indeed stale:

var expires = Titanium.App.getInt('expires');

// Get the current time in milliseconds, etc.

if(expires > current_time) {
    // Cache is still valid
    var response = Titanium.App.getString('jsonResponse');
    var obj = JSON.parse(response);
}
else {
    // Cache is stale - query for new data
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜