Caching Query Results with QueryArrayCached

If your application has a component that needs to issue the same query multiple times, you should know about QueryArrayCached. This method is identical to QueryArray, except that the results of your query will be stored in the QCache object, and if there's a match, the query won't be sent to the database server - cached results will be used instead.

Why is this cool? Because this can give you amazing performance improvements. What if your page has a list of product categories that rarely changes? And that list appears on a highly-trafficked page on your site? Just change your query calls to use QueryArrayCached method, and the rest will be taken care of for you.

In the example below, pay attention to the Number of Queries performed at the very bottom - the first time you load this page, two queries; subsequent page reloads will not cause any queries at all. That is, of course, until you clear the cache - you can do so by passing in a $blnForceUpdate parameter set to true to QueryArrayCached, or by using the QCache::ClearNamespace() method - see more in the sample code of this example.

You should also be aware of persistent controls (example) - a higher-level abstraction that allows you to cache entire QControls.

   

Items in the Persons table:
kavita 2 arulyfred
Kendall2 Publics
Ben 5665564
Mike Ho
Alex Smith
Wendy Smith
Karen Wolfe
Samantha Jones
Linda Brady
Jennifer Smithfgfg
Brett Carlisle j
Jacob Pratt
sdf sdf
sdhgfhsdg jai
billy wilder
Nice Job
good job
moi tpo77
test test

PROFILING INFORMATION FOR DATABASE CONNECTION #1: No queries performed. Please click here to view profiling detail