I have several web sequential pages which will modify a record and its child records in the database, called a “project”. Such a project is currently passed between pages using its database ID in the URL parameters.
A project has some information specific to itself, and also consists of one or more Tasks, which each have information specific to itself.
Is it faster (alternatively, more maintainable or more easily understood) to hit the database each time I need to query the same project (and its tasks), or should I query the database once (either once for each page or once for all pages and save to Session) and check the saved object rather than the database?
Note that I am asking about checking data, not saving it (I will still hit the database each time I need to save something, obviously).
Put the database ID in the session and get the rest from the database. Is the database and the web server on the same hardware, if so that database will cache those results anyway, and it should return that data fairly fast?
I assume your taking about a simple site, if your talking about twitter/facebook scale, you’ve got a lot more to worry about then where to store your data.
Two ideas:
This will allow you to hit that
database for your data, while not
looking like you are 🙂
try it. Try it out, hit the
database for project details 1000
times, and get your stopwatch out.
Often times questions like this depend on so many variables it’s hard to give a straight answer. If you’ve got a lot of data, a project with 10,000 tasks, well that’s going to be a bad idea to store in the session. If you’re just asking about storing database ID and a project name, well then I’d say store it in the session.