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
This will require only serializable data to be used within this. Consider using dill.pickle to serialize data more robustly than standard library.
The state should only be fetched from the database once, upon first initialization of the hook's state value. On every set_state call, the value should be synchronized to the database.
We may want to document that the user should regularly purge old sessions.
This implementation will require the use of database-backed sessions or django.contrib.sessions.backends.cached_db.
Example Database Model
classIdomSessionState(models.Model):
# One state is stored per user browser session# When the browser session expires, the state is deleted from the databasesession=models.ForeignKey(Session, on_delete=models.CASCADE)
state=models.BinaryField(blank=True, null=True)
The interface may look like this...
# Note: The default state is only used in situations where there is no value in the database# The websocket is needed in order to grab the session from the `scope`state, set_state=hooks.use_session_state({"foo":"bar"}, websocket=websocket)
print(state.data)
# This saves the values to the databaseset_state({"something":"else"})
In the background, the set state is doing the following...
Activity
[-]useSessionContext Hook[/-][+]useSessionState Hook[/+][-]useSessionState Hook[/-][+]use_session_state Hook[/+][-]use_session_state Hook[/-][+]`use_session_state` hook[/+]