简体   繁体   English

Phoenix Framework的Plug.Conn中assign和put_session有什么区别?

[英]What is the difference between assign and put_session in Plug.Conn of the Phoenix Framework?

The documentation ( https://hexdocs.pm/plug/Plug.Conn.html ) names two functions that allow for storing a key-value pair in a conn 文档( https://hexdocs.pm/plug/Plug.Conn.html )命名两个函数,允许在conn存储键值对

assign(conn, key, value)

Assigns a value to a key in the connection 为连接中的键分配值

put_session(conn, key, value)

Puts the specified value in the session for the given key 将指定值放在给定键的会话中

What is the difference between these two functions? 这两个功能有什么区别?

Basically assign works only for particular connection - Plug.Conn structure - which means that this value would be gone with the end of the request - as conn will also dies - at the end of the request / response cycle. 基本上, assign只适用于特定的连接 - Plug.Conn结构 - 这意味着在请求/响应周期结束时,该值将随着请求的结束而消失 - 因为conn也会死亡。

Session lives longer and it's stored in cookies or in ets. 会话寿命更长,并存储在cookie或ets中。 Thanks to that you keep eg. 多亏了你保持eg。 data about the successfully logged in user across the requests. 有关跨请求成功登录用户的数据。

TL;DR: TL; DR:

assign works for each request and it's wipe out after the end of the request cycle. 每个请求assign工作,并在请求周期结束后消除。

put_session inserts a value in the session and it's available until the session is cleared / expired. put_session在会话中插入一个值,直到会话清除/过期才可用。

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

相关问题 如何让 put_session 持续更长时间? - How to make put_session last longer? Session 和 Cookie 有什么区别? - What is the difference between a Session and a Cookie? Play框架会话和PHP会话之间的区别 - Difference between Play Framework Session and PHP Session SQLALchemy的会话和postgresql的会话有什么区别? - What is the difference between the session of SQLALchemy and that of postgresql? 在IIS中,“应用程序”和“会话”之间有什么区别? - in IIS, what's the difference between “application” and “session”? Hibernate 中的会话和连接有什么区别? - What is the difference between a Session and a Connection in Hibernate? $ _ENV,$ _SESSION和$ _COOKIE之间有什么区别? - what is the difference between $_ENV , $_SESSION and $_COOKIE NHibernate 中的 StatelessSession 和 Session 有什么区别? - What is the difference between StatelessSession and Session in NHibernate? session.Merge和session.SaveOrUpdate有什么区别? - What's the difference between session.Merge and session.SaveOrUpdate? Session.Abandon()和Session.Clear()之间的区别是什么 - What is the difference between Session.Abandon() and Session.Clear()
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM