Title:
Bug 81846:(Watson Migration Closure)Fragment Cache GotchaI was just playing around some more with the template cache in ColdFusion 9 and noticed a behavior I hadn't expected that I think could potentially cause problems for people down
| View in TrackerStatus/Resolution/Reason: To Fix//
Reporter/Name(from Bugbase): Rob Bilson / Rob Brooks-Bilson (Rob Bilson)
Created: 01/28/2010
Components: Caching
Versions: 9.0
Failure Type: Unspecified
Found In Build/Fixed In Build: 0000 /
Priority/Frequency: Minor / Unknown
Locale/System: English / Platforms All
Vote Count: 2
Problem:
Fragment Cache GotchaI was just playing around some more with the template cache in ColdFusion 9 and noticed a behavior I hadn't expected that I think could potentially cause problems for people down the road.Consider the following example:<cfcache>This is a fragment</cfcache><cfcache><cfoutput>And so is this #now()#</cfoutput></cfcache><cfdump var="#getalltemplatecacheids()#">If you execute this, you'll get some output as well as a dump of all of the cached items in the template cache (getalltemplatecacheids is an undocumented function). At this point, there are two items in the cache: Now say you weren't happy that the two lines of output on your page were all run together and you wanted to put a line break between each one. You might modify your code and add in a simple paragraph tag or line break like so:<cfcache>This is a fragment</cfcache><p><cfcache><cfoutput>And so is this #now()#</cfoutput></cfcache><cfdump var="#getalltemplatecacheids()#">Go ahead and run the code once you've inserted the <p> tag. What you'll now see is that you have three items in the cache: What's happening is that ColdFusion is using the position of the code in your page as part of the ID for the cached item. When you inserted the <p> tag, the position of the fragment you cached also changed by moving down a few lines, and ColdFusion assumed you had added a new page fragment that you wanted to cache.This may or may not be a big deal to people as CF will still pull the correct cached item every time. The gotcha is that if you have a lot of caching going on, and you're making a lot of changes in a development environment, it's possible to fill your cache up with a lot of junk pretty quickly.I'm not making any statements on how this feature was implemented - I just want to make people aware of how the template cache works under the covers since it's not documented and if people are paying attention when they are developing they might see some things with the template cache that don't make sense if they don't know how it works.My suggestion here is that the docs be updated to explain this behavior and make any necessary recommendations for avoiding in prodiuction. Or do as a tech note.
Method:
Result:
----------------------------- Additional Watson Details -----------------------------
Watson Bug ID: 3040849
External Customer Info:
External Company:
External Customer Name: Rob Brooks-Bilson
External Customer Email: 6B546ECA439559160AAC0C16
External Test Config: 01/28/2010
Attachments:
Comments: