无状态 Web 应用程序的好处是什么? [英] What are the benefits of a stateless web application?

查看:56
本文介绍了无状态 Web 应用程序的好处是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎有些网络架构师的目标是拥有一个无状态的网络应用程序.这是否意味着基本上不存储用户会话?或者还有更多吗?

It seems some web architects aim to have a stateless web application. Does that mean basically not storing user sessions? Or is there more to it?

如果只是存储用户会话,不这样做有什么好处?

If it is just the user session storing, what is the benefit of not doing that?

推荐答案

  1. 减少内存使用.想象一下,如果谷歌存储了每个用户的会话信息
  2. 更容易支持服务器群.如果您需要会话数据并且您有 1 个以上的服务器,则需要一种跨服务器同步会话数据的方法.通常这是使用数据库完成的.
  3. 减少会话过期问题.有时,过期会话会导致难以发现和测试的问题.无会话应用程序不会受到这些影响.
  4. 网址链接.一些站点存储用户在会话中查看的内容的 ID.这使得用户无法简单地复制和粘贴网址或将其发送给朋友.
  1. Reduces memory usage. Imagine if google stored session information about every one of their users
  2. Easier to support server farms. If you need session data and you have more than 1 server, you need a way to sync that session data across servers. Normally this is done using a database.
  3. Reduce session expiration problems. Sometimes expiring sessions cause issues that are hard to find and test for. Sessionless applications don't suffer from these.
  4. Url linkability. Some sites store the ID of what the user is looking at in the sessions. This makes it impossible for users to simply copy and paste the URL or send it to friends.

注意:会话数据实际上是缓存数据.这是它应该被用来做什么.如果您有一个要重用的昂贵查询,请将其保存到会话中.请记住,当您稍后尝试获取它时,您不能假设它会在那里.在检索之前始终检查它是否存在.

NOTE: session data is really cached data. This is what it should be used for. If you have an expensive query which is going to be reused, then save it into session. Just remember that you cannot assume it will be there when you try and get it later. Always check if it exists before retrieving.

这篇关于无状态 Web 应用程序的好处是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆