A generic session stash is less telepathic.

11 views
Skip to first unread message

Terrence Brannon

unread,
Oct 24, 2018, 3:26:22 AM10/24/18
to Reahl discuss
It is very unusual to declare your sessionable data ahead of time like Reahl requires via @session_scoped. Also, what sort of data structures are efficiently persisted in a session_scoped object? I.e., can nested JSON documents or Python dictionaries with arrays of values be stored?

It seems that one might prefer to create a generic key-value call and store any and everything in your app in it:

@session_scoped
class SessionStash(Base):

    key = Column(UnicodeText)
    value = Column(UnicodeText)


And then you just pop whatever data you want in the SessionStash and then pull it out.


Iwan Vosloo

unread,
Oct 25, 2018, 2:03:38 AM10/25/18
to reahl-...@googlegroups.com
On 2018/10/24 09:26, Terrence Brannon wrote:
> It is very unusual to declare your sessionable data ahead of time like
> Reahl requires via @session_scoped. Also, what sort of data structures
> are efficiently persisted in a session_scoped object? I.e., can nested
> JSON documents or Python dictionaries with arrays of values be stored?
>

@session_scoped only works with classes persisted using SqlAlchemy.

This means that you can have SqlAlchemy-modelled relationships to your
other (non-session-scoped) objects. It does incur the overhead that you
cannot just persist ANY object to session cache.

It means also that if you scale up to have many web servers (possibly on
different physical machines) your @session_scoped objects are available
on each machine without any different programming of setup required.

I don't know what the performance penalties are, but I feel dealing with
that is the responsibility of the database (which can usually also be
scaled up and tweaked in many ways).

Using a different persistence mechanism for caching session-based data
feels a bit inconsistent to me. So I'd rather work on other things and
gather some more experience before I want to go in that direction.

> It seems that one might prefer to create a generic key-value call and
> store any and everything in your app in it:
>
> @session_scoped
> class SessionStash(Base):
>
> key = Column(UnicodeText)
> value = Column(UnicodeText)
>
>
> And then you just pop whatever data you want in the SessionStash and
> then pull it out.

This is of course possible, perhaps with Blob values, and Python objects
that can be pickled. You could have something like a
"@session_scoped(PickleJar)" that stores key, pickled_value objects as
you suggest above.

Based on my argument above though, I'd want to see more use cases to get
a better understanding / motivation for something like this.

-i

--


Reply all
Reply to author
Forward
0 new messages