You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Applications often want to persist data from the lifespan cycle to request/response handling. For example, a database connection can be established in the lifespan cycle and persisted to the request/response cycle. The scope["state"] namespace provides a place to store these sorts of things. The server will ensure that a shallow copy of the namespace is passed into each subsequent request/response call into the application. Since the server manages the application lifespan and often the event loop as well this ensures that the application is always accessing the database connection (or other stored object) that corresponds to the right event loop and lifecycle, without using context variables, global mutable state or having to worry about references to stale/closed connections.
In Falcon apps, another alternative is simply storing data inside resource or middleware attributes, but it might be still nice to make use of this state, e.g., to interact with generic middleware etc.
The text was updated successfully, but these errors were encountered:
The ASGI Lifespan Protocol offers Lifespan State (if the app server supports it):
In Falcon apps, another alternative is simply storing data inside resource or middleware attributes, but it might be still nice to make use of this
state
, e.g., to interact with generic middleware etc.The text was updated successfully, but these errors were encountered: