简体   繁体   English

REST Web API应用程序数据管理

[英]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: 我不能决定如何管理应用程序中地址的数据,我应该:

  1. 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 该请求将包含更多数据并且更大,但是我不需要将所有工作站都放在服务器上

  2. 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 请求将包含较少的数据量,但我需要获取服务器上的所有地址

  3. 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: 没有适用于所有情况的灵丹妙药,但我建议您采用以下方式:

  1. Load all addresses to client. 将所有地址加载到客户端。 Most probably end user prefer to see detailed address information instead of meaningless ids 最终用户很可能希望查看详细的地址信息,而不是无意义的ID
  2. After user selected destination your app send only ids to server 用户选择目标后,您的应用仅将ID发送到服务器
  3. Server have to take address details by ids from db 服务器必须通过db中的id获取地址详细信息
  4. Send letter 发信

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: 例:

  1. Create repository that fetch addresses from db 创建从数据库获取地址的存储库
  2. Create repository wrapper that take data from DB just once and then keep in MemoryCahce strucutre 创建仅需一次从数据库获取数据的存储库包装,然后将其保存在MemoryCahce strucutre中
  3. Use cached wrapper in you application 在应用程序中使用缓存的包装器

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

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