Skip to main content
Participating Frequently
January 7, 2015
Answered

Coldfusion 11 - Clear database cache

  • January 7, 2015
  • 1 reply
  • 2845 views

Hi

We've just upgraded to CF11 update 3 on a 64bit Windows 2008 Server from CF10 and have found that my previous code to clear cached database queries no longer works as instantly or reliably as it did previously.

I'm currently using the following code in my application.cfc file.

This code would run if I were to hit the following page on the website... index.cfm?reinit=yes

<cffunction name="onRequestStart" hint="">

<cfif structKeyExists(URL, "reinit")>

<cfset cacheRemoveAll()> <!--- Added 7th Jan 2015 without improvement--->

<cfset onApplicationStart()>

<cfobjectcache action="clear">

</cfif>

</cffunction>

Here's an example of a query I'm trying to clear the cache of

<cfquery name="rs_Issue" datasource="#APPLICATION.dsource1#" cachedwithin="#CreateTimeSpan(0,1,0,0)#">

SELECT Issue_ID, Issue_Name

FROM Issue

WHERE Issue_Status = <cfqueryparam cfsqltype="cf_sql_varchar" value="Current">

</cfquery>

Has anyone got any suggestions of what I'm doing wrong to clear the database cache (either application or server wide)?

Thanks

Stuart

This topic has been closed for replies.
Correct answer BKBK

stuartw81 wrote:

<cffunction name="onRequestStart" hint="">

<cfif structKeyExists(URL, "reinit")>

<cfset cacheRemoveAll()> <!--- Added 7th Jan 2015 without improvement--->

</cfif>

</cffunction>

You may have to go from the general to the specific. By default, ColdFusion caches queries in a 'region' of the cache named 'query'. You should therefore use cacheRemoveAll('query') in place of cacheRemoveAll().

1 reply

BKBK
Community Expert
BKBKCommunity ExpertCorrect answer
Community Expert
January 8, 2015

stuartw81 wrote:

<cffunction name="onRequestStart" hint="">

<cfif structKeyExists(URL, "reinit")>

<cfset cacheRemoveAll()> <!--- Added 7th Jan 2015 without improvement--->

</cfif>

</cffunction>

You may have to go from the general to the specific. By default, ColdFusion caches queries in a 'region' of the cache named 'query'. You should therefore use cacheRemoveAll('query') in place of cacheRemoveAll().

stuartw81Author
Participating Frequently
January 8, 2015

Thanks BKBK, that worked first time!

Many thanks for your help.

Kind regards

Stuart

BKBK
Community Expert
Community Expert
January 8, 2015

Glad to hear. Best wishes.