> The select list may need to be rebuilt a number of times as the user refines > their search. The query won’t vary and the likelihood that the results will > vary are low enough that saving the results in a session variable is > acceptable. I’d expect that the user would peruse the results for 10 to 60 > seconds before refining their search. > > My question is: should I save the query results in a session variable for > reuse or is the database efficient enough to cache the query results?
Unless you have significant load, don't cache. This applies to sticking things in sessions, putting them in memcache, on filesystems, whatever. The reason for this is that the act of caching creates a potential inconsistency between the authoritative data source, and the various systems that can interact with it. This can lead to some particularly difficult-to-diagnose rare errors and nasty corner cases. So the answer to your question is: start by going back to the database each time, that way your chances of getting into those situations is minimised. Then, if you find yourself facing load issues, you can start worrying about the complexity created by a cache at that point, and decide where to put it. For reference, a reasonable spec machine can perform many hundreds to thousands (depending on the precise nature) of db queries per second. Far fewer app developers need to worry about caching than is commonly believed. Regards, Richard. -- NZ PHP Users Group: http://groups.google.com/group/nzphpug To post, send email to [email protected] To unsubscribe, send email to [email protected]
