Not an answer, but Why don't you want flash messages etc in the dB - it shows user activity which I think you are trying to track? In addition sessions in dB makes scaling easier
Flash data like "Success! Your message has been sent" is transient and doesn't need to incur a hit on the database. It literally doesn't need to last for more than one request, whereas an authenticated session might last 2 hours or more and contain more meaningful data related to my business rules.
User activity would be tracked by simply recording the app/module/component/content_id (or even just the URI) the user's last request was on. Basically the MAIN reason to track user sessions is so that when you're viewing say, a forum post or an article, it shows you that 17 or 30 people are currently viewing that post, or that there are 482 users active in the last 15 minutes etc. There's no need for flash data to be available to anyone but the user who the flash message is intended for, so storing it in a database and doing garbage collection on it the very next request is unnecessary overhead IMO.
Even things like the valid input for some form fields when a form error is present (e.g. username is valid, but email was invalid, so keep the valid username when the form redirects with errors) uses the session, so storing that in the database is again a bit pointless.
How will you avoid garbage collection by storing transient session values away from the database? I assume you would be using the file system so would still need to do this?
I guess you could build your own session handler for flash data that writes to the file system, or if you really want to avoid garbage collection on the server look at passing transient data in cookies (urgh!), but again you would still need to handle garbage collection of the cookie.
Are you getting a noticeable performance hit when storing transient data in the db session?
Sign in to participate in this thread!
We'd like to thank these amazing companies for supporting us
The Laravel portal for problem solving, knowledge sharing and community building.