android - 服务端数据更新,如何更新客户端缓存
黄舟
黄舟 2017-04-18 09:49:08
0
4
415

我是服务端

被客户端吐槽说我的API接口没有数据版本号(用来表示后台数据是否有更新),导致客户端缓存不知道什么时候更新,每次都要请求服务端数据

对此有几点疑虑,特来请教各位大拿

  1. 客户端缓存更新是否真的有必要依赖服务端的通知?

  2. 如果增加版本号这种需求成立,难道需要每次服务端更新数据都要更新版本号?感觉并不是优雅的设计

  3. 目前处于项目初期,是否可以考虑根据具体业务数据更新频度,客户端自己设计更新策略

  4. 如果服务端数据变动通知真的是强需求,我考虑使用Last-Modified 与If-Modified-Since等Http Header的方式,是否可行

  5. 有没有其他的解决方案,还请赐教

黄舟
黄舟

人生最曼妙的风景,竟是内心的淡定与从容!

reply all(4)
迷茫

For this kind of data part that is sensitive to update changes, create_time and update_time fields can be added to the database design. When the content is modified, the value of the update_time field is updated at the same time.

Let the customer handle the rest by themselves. The interface does not need to carry the API version number.

巴扎黑
  1. Think about it, is there any way for the client to know that your server’s data has been updated?

  2. The prerequisite for thinking that something is not elegant is that you can find something more elegant.

  3. This depends on your data synchronization requirements. If the synchronization requirements are high, the server must notify you.

迷茫

First of all, the definition of cached data here is data that is not updated for a long time and is rarely updated. Such as provinces, cities and regions, fixed configuration items, user authentication information (basically not updated).
So for our current project, the client calls the server interface every time it is initialized, passes an update_time, and then the server checks the database based on this update_time to determine whether the current data has been updated. If not, it will be sent to the client. The client returns empty, and then the client gets the local cached data.

阿神

Let the front end call the API regularly to transmit the last updated time. The API determines the last updated time based on the database, and returns data to the front end if it is not the last updated time

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template