Reputation: 430
I'm making a php web application which stores user specific information that is not shared with other users.
Would it be a good idea to store some of this information in the $_SESSION variable for caching? For example: cache a list of categories the user has created for their account.
Upvotes: 10
Views: 9816
Reputation: 9540
If you only want this data available during their session, then yes. If you want it available tomorrow, or 4 hours from now, you need to save it to a database.
Technically you can modify the sessions to have a very long lifespan, but realize if they use a different computer, a different browser or flush their cookies they will loose the link to their session, therefore anything serious you should create a type of user account in your application, link the session to their account and save the data in a permeate place.
Upvotes: 2
Reputation: 41827
That could work well for relatively small amounts of data but you'll have to take some things into consideration:
Upvotes: 4
Reputation: 11211
This would be an appropriate use of the session mechanism as long as you keep this in mind:
A good usage pattern would be like this (ether cookies or session):
Things not to do in a cookie
I'm sure there is other things to consider too, but this is just off the top of my head here.
Upvotes: 13