Dans un troquet après la réunion CF de novembre (ou décembre:)
Je crois me souvenir avoir aborder, (avec eric si mes souvenirs sont bons) un débat sur l'utilité de la mise en cache de query of query pour trier un jeu de résultat.
Je voulais juste vous donner un exemple qui illustre ces propos :
- <!--- PARAMETRES--->
- <cfapplication sessionmanagement="true" name="LordRhumSifflar_Application">
- <cfset listChamps="A,B,C">
- <!--- NOM DE LA REQUETE DOIT ETRE UNIQUE ENTRE SESSION--->
- <cfset qCached = "nomDeMaRequete#SESSION.cfid#">
- <cftry>
- <!--- TENTE LA RECUPERATION DE LA REQUETE EN CACHE--->
- <cfquery cachedwithin="#CreateTimeSpan(0, 0, 0, 13)#" name="#qCached#" dbtype="query" >
- SELECT * FROM q
- </cfquery>
- <cfcatch >
- <!--- SI LA REQUETE N EXISTAIT PAS (timeout) (premier chargement)--->
- <!--- CREATION D UNE REQUETE--->
- <cfset q = queryNew("#listChamps#","Integer,Integer,Integer")>
- <cfloop from="1" to="10" index="index">
- <cfset QueryAddRow(q,1)>
- <cfloop list="#listChamps#" index="champs">
- <cfset querySetCell(q,"#champs#",RandRange(index-5,index),index)>
- </cfloop>
- </cfloop>
- <!--- MISE EN CACHE DU JEU DE RESULTAT (13 sec)--->
- <cfquery cachedwithin="#CreateTimeSpan(0, 0, 0, 13)#" name="#qCached#" dbtype="query" >
- SELECT * FROM q
- </cfquery>
- </cfcatch>
- </cftry><!---<cfdump var="#Evaluate(qCached)#" label="jeu de résultat à sauvegarder.">
- --->
- <cfquery name="qRequeteTrier" dbtype="query" >
- SELECT * FROM #qCached#
- <cfif IsDefined("url.ChampsATrier") >
- ORDER BY #url.ChampsATrier#
- </cfif>
- </cfquery>
- <!--- SORTIE HTML --->
- <cfoutput>
- <table border="1" cellpadding="10">
- <cfloop query="qRequeteTrier">
- <cfif qRequeteTrier.currentRow EQ 1>
- <tr><th colspan="#ListLen(listChamps)#">RESULTAT :</th></tr>
- <tr><td colspan="#ListLen(listChamps)#"><cfif IsDefined("url.ChampsATrier")>Trié par : #url.ChampsATrier#</cfif><br /></td></tr>
- <tr>
- <cfloop list="#listChamps#" index="champs">
- <th><a href='?ChampsATrier=#champs#'>#champs#</a></th>
- </cfloop>
- </tr>
- </cfif>
- <tr>
- <cfloop list="#listChamps#" index="champs">
- <td>#Evaluate("qRequeteTrier.#champs#")#</td>
- </cfloop>
- </tr>
- </cfloop>
- </table>
- </cfoutput>
A bientôtô

CFforum.eu | Coldfusion Forum