Skip to main content
Participant
Jul 24, 2018 5:57 PM UTC
Question

CF9 CFCache and ID

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 is closed to new replies. Start a new post to keep the conversation going.

2 replies

BKBK
Community Expert
Community Expert
Aug 19, 2018 4:12 PM UTC

Hi @Brian Kondalski, did the above suggestion help?

Translate
BKBK
Community Expert
Community Expert
Aug 12, 2018 4:45 PM UTC

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>

Translate