Skip to content

How to efficiently store a DBIx::Class object in session ? #2163

Answered by rabbiveesh
fluca1978 asked this question in Q&A
Discussion options

You must be logged in to vote

I wouldn't recommend trying to store an object in the session for a few reasons:

  1. the session cookie is signed, not encrypted, so you may end up bleeding data that you didn't want to
  2. you can't actually do what you want to - you'd have to serialize the object to json via a TO_JSON method, which you'd still have to make back into a proper object on your side
  3. data may get stale - this isn't really an issue for the stash, b/c that's a perl value that only exists for your req/res cycle (which, to be fair, could still get stale, but you can handle that better), whereas the cookie may last until it expires (a week, a month?)

What you have there is the best option, just store a PK in the session…

Replies: 5 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by fluca1978
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants