The situation is a bit more complicated, with cachedwithin you have the
power of caching + defining the expiration. The negative effect of
cachedwithin is that it uses a first in first out system, because
ColdFusion has only has a maximum amount of cached queries it can hold
(defined in the cf administrator). This means if you have cached queries
in a website not related to a search, those cached queries could be
released because of a search cached query.
With application variables you have practically unlimited space to store
cached queries in. It is more like this
<cfset variableName = "cq" & Hash(form.string)>

<cfif NOT IsDefined('application.#variableName#')>
<cfquery name="application.#variableName#" dsn="#myDSN#">
EXEC sp_search
@string = '#form.string#'
</cfquery>

<cfset tmp = structNew()>
<cfset tmp ["expiration"] = CreateTimeSpan(0,0,5,0)>
<cfset tmp ["variableName"] = variableName>
<cfset ArrayAppend(application.cachedQueries, tmp)>
</cfif>

<cfoutput query="application.#variableName#"></cfoutput>

You only need to make a function which cleans up the application scope
of expired caches, because the application scope is by default active
more than 5 minutes.

Micha Schopman
Software Engineer
Modern Media, Databankweg 12 M, 3821 AL  Amersfoort
Tel 033-4535377, Fax 033-4535388
KvK Amersfoort 39081679, Rabo 39.48.05.380
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]

Reply via email to