dsgtew3241 2015-10-08 15:26
浏览 32
已采纳

too long

Background

I have an iOS app that retrieves data from a server and writes it to a file with NSFileManager, so that the user does not have to retrieve data again from the server every time they want to visit a page. The data that they are retrieving can change from time to time, so I would like to update the data in the app files when it does.

I am using php pages for my backend web services.

Question

What is the technique for checking if the data in my database has changed so that I know that I should update the data in the app? The only way I can think to do this is to create a php page that checks if the data is different from what I have stored, but this kind of defeats the purpose of saving information to files within the app. I want to minimize when the user communicates with the server, because in situations where the user has no service, I would still like there to be valid data that they can see within the app.

Please ask questions if you do not fully understand what I am trying to achieve. Thank you!

  • 写回答

2条回答 默认 最新

  • dqk77945 2015-10-08 15:50
    关注

    If you want to list the most recently added restaurants for example, you could :

    • Store the ID of the most recent restaurant on IOS and send it to the server when you want to check for updates.
      • If the ID isn't the same in the DB, then you have to update your client.
      • If it's the same, you can just send a response with a 304 status (Not modified) so you minimise the amount of data being exchange.

    If you want to cache computed data, like top 10 user-rated restaurants, you can :

    • Store a hash of the 10 restaurant IDs and send it to server when you want to check for updates.
    • The server redo the request and compute the current hash for the top 10.
      • If the hash is different, update your client
      • If the hash is the same, send a response with a 304 status

    NB : If the computation is expensive on server side, you might want to think about a more clever way to detect data changes.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 制裁名单20240508芯片厂商
  • ¥20 易康econgnition精度验证
  • ¥15 线程问题判断多次进入
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接