I’m running a web application that allows a user to log in. The user can add/remove content to his/her ‘library’ which is displayed on a page called “library.php”. Instead of querying the database for the contents of the users library everytime they load “library.php”, I want to store it globally for PHP when the user logs in, so that the query is only run once. Is there a best practice for doing this? fx. storing their library in an array in a session?
Thanks for your time
If you store each user’s library in a
$_SESSIONas an array, as you suggested (which is definitely possible) you will have to make sure that any updates the user makes to the library are instantly reflected to that session variable.Honestly, unless there is some seriously heavy querying going on to fetch a library, or you have tons of traffic, I would just stick to ‘execute query whenever the user hits library.php’.