Skip to main content
Participant
July 24, 2018
Question

CF9 CFCache and ID

  • July 24, 2018
  • 2 replies
  • 564 views

I'm running CF9 currently and trying to cache a fragment of a page.  This fragment is dependent on a region code, so I want to cache it with a different cache ID for each region.  The region code is in a variable.  So I am trying to do the following in the page:

<CFSET RegionID = 100>

<CFCACHE action="cache" ID="#RegionID#" timespan="#CreateTimeSpan(1,0,0,0)#">

This is the content I want to cache for Region: <CFOUTPUT>#RegionID#</CFOUTPUT>

</CFCACHE>

However it does not look like CF is using the value of the RegionID variable as the ID for the cached entity.  But it is actually using the string "#RegionID#" as the ID.  I can find this to be true by simply changing the RegionID value and I still get the same cached content as I had for the previous cache.  So I can not cache it for each region differently!

Am I doing something wrong?  A different approach perhaps?

This topic has been closed for replies.

2 replies

BKBK
Community Expert
Community Expert
August 19, 2018

Hi @Brian Kondalski, did the above suggestion help?

BKBK
Community Expert
Community Expert
August 12, 2018

Cfcache's ID attribute identifies the object you are caching, not the region. You have to define the region beforehand.

Then pass the region-ID as a separate attribute. I would do something like

<!--- Define new region, with ID 'Region100'--->

<cfset properties=structNew()>

<cfset properties.name="Region100">

<cfset cacheSetProperties(properties)>

<!--- Object 'myCachedObjectId' is cached in 'Region100' --->

<cfcache action="cache" id="myCachedObjectId" timespan="#CreateTimeSpan(1,0,0,0)#" region="Region100">

This is the content I want to cache for Region100

</cfcache>