[英]REST Web api application data managment
I'm pretty confused about how should Manage the data in the RESTful web application I develop. 我对应该如何在开发的RESTful Web应用程序中管理数据感到非常困惑。 How much of the data should be saved on client side? 客户端应保存多少数据?
For a more specific example: 有关更具体的示例:
My application sends letters from one system to another. 我的应用程序将信件从一个系统发送到另一个系统。 I save the letters on server side using Sql server. 我使用Sql server将字母保存在服务器端。 For each letter there are destinations and the source represented by Address object containing full information about the the Addresses. 对于每个字母,都有一个目的地和由Address对象表示的来源,其中包含有关Addresses的完整信息。 I can't decide how should I manage the data of the Addresses in my application, should I: 我不能决定如何管理应用程序中地址的数据,我应该:
load all the Addresses to my client on start up and with each letter sendding stick the entire Addresses list to the reqeust? 在启动时将所有地址加载到我的客户端,并且随着每个字母的发送将整个地址列表粘贴到要求中? The request will contain more data and be bigger but I won't need to get all the stations on server 该请求将包含更多数据并且更大,但是我不需要将所有工作站都放在服务器上
load to client only the Id's of the addresses and send requests with Ids and then load them from a database on server side? 仅将地址的ID加载到客户端,并使用ID发送请求,然后从服务器端的数据库加载它们? Requests will contain smaller amount of data but I will need to fetch all Addresses on server 请求将包含较少的数据量,但我需要获取服务器上的所有地址
Should I save on the client only the Address object representing his own Address and the other stations id's? 我应该只在客户端上保存代表其自己的地址以及其他工作站ID的Address对象吗? Same as 2 but I won't need to fetch the Address of the sender 与2相同,但我不需要提取发件人的地址
What are the pros/cons of each method? 每种方法的优点/缺点是什么? What would you choose in case the number of stations is around 100 (without so much data within each object) 万一站数约为100(每个对象中没有太多数据)时,您会选择什么?
I'm no professional so please correct me if anything I said was wrong/silly wording 我不是专业人士,所以如果我说的话有误/措词不对,请纠正我
Thanks in advance. 提前致谢。
There is no silver bullet that works in all cases but i would suggest you to do it in next way: 没有适用于所有情况的灵丹妙药,但我建议您采用以下方式:
Client should not send full address object as it might be (accidentally or by purpose) wrong.you should better always take real and valid data from DB. 客户端不应发送完整的地址对象,因为它可能是(偶然或有意)错误的。您最好始终从数据库获取真实有效的数据。 If you need to reduce load on DB you should better use server side caching. 如果需要减少数据库负载,则最好使用服务器端缓存。 Example: 例:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.