简体   繁体   English

Android在一定时间限制内缓存网络响应

[英]Android caching network response for certain time limit

I am currently using HttpClient to perform a network request which returns a JSON object. 我目前正在使用HttpClient执行网络请求,该请求返回JSON对象。 I would like to cache the data that comes back and set an expiration of ten minutes to that cached data. 我想缓存返回的数据,并为该缓存的数据设置十分钟的到期时间。

I have looked into using LruCache, SQLite, and shared preferences. 我研究了使用LruCache,SQLite和共享首选项。 Which would be the best way to perform this task? 哪一种是执行此任务的最佳方法? I am currently using an SQLite database for other parts of my app, so I was just thinking about using that and comparing the timestamp when the data was cached. 我目前正在将SQLite数据库用于应用程序的其他部分,因此我只是在考虑使用该数据库,并比较缓存数据的时间戳。 That option will work for me, but seems like overkill since there will always only be one row in that table. 该选项对我有用,但似乎有点过头了,因为该表中总是只有一行。

Any suggestions will be helpful. 任何建议都会有所帮助。 Thanks! 谢谢!

共享的首选项非常简单,足以满足您的需求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM