Hi,
I've been playing around with the view caching in ColdBox 3 RC 1, and
have found when I pass a value to the cacheSuffix argument of render
view it doesn't seem to cache the view. Is this a bug or am I not
understanding how it works?
Here's a quick example:
component
{
void function cachedviewtest( required event )
{
var rc = arguments.event.getCollection();
// get the template cache
var TemplateCache = getColdboxOCM( "template" );
// set the view we want to render
var theview = "general/cachedviewtest";
// create a suffix for this event to identify in the cache
var cachesuffix = "foobar";
writeDump( var=TemplateCache.GETKEYS(), output="console" );
writeDump( var="exists? " & TemplateCache.lookup( "cbox_view-general/
cachedviewtestfoobar" ), output="console" );
writeDump( var="exists? " &
TemplateCache.lookup( "#TemplateCache.getViewCacheKeyPrefix()##theview##cachesuffix#" ),
output="console" );
arguments.event.setView( name=theview, cache="true",
cacheTimeout="5", cacheLastAccessTimeout="5",
cacheSuffix=cachesuffix );
}
}
My cachedviewtest.cfm view is a simple output of #now()#
When I run it this first time I get this in my console:
[localhost CF9.01]:array [empty]
[localhost CF9.01]:exists? false
[localhost CF9.01]:exists? false
The browsers shows the current timestamp, which is what I'd expect.
However if I run it again I get the new current timestamp in the
browser, but the console shows:
[localhost CF9.01]:array - Top 1 of 1 rows
[localhost CF9.01]:1) cbox_view-general/cachedviewtestfoobar
[localhost CF9.01]:exists? true
[localhost CF9.01]:exists? true
If I set the cacheSuffix argument passed to renderView to an empty
string, then the the timestamp does not update in my browser and my
console shows:
[localhost CF9.01]:array - Top 1 of 1 rows
[localhost CF9.01]:1) cbox_view-general/cachedviewtest
[localhost CF9.01]:exists? false
[localhost CF9.01]:exists? true
So it seems to me that if you set the cacheSuffix, then the view is
correctly store in the cache, but is not retrieved from it again. This
is also confirmed by the debugging info which says:
rendering Cached View [general/cachedviewtest.cfm]
When I set the suffix to an empty string, but shows:
rendering View [general/cachedviewtest.cfm]
When I do set the suffix to any string.
As a side note, which may help. If I run the event with a blank suffix
and then change the suffix to #Rand()#, it always renders a cached
view. Am I completely misunderstanding what the suffix argument is
for?
Thanks,
- John