Ticket #389 (new defect)

Opened 16 years ago

Last modified 16 years ago

ColdFusion 9's new "Cache Template in Request" admin setting breaks event generation

Reported by: cfgrok Owned by:
Priority: normal Milestone: 3.2
Version: 3.1.185 Severity: normal
Keywords: event-generation Cc:

Description

ColdFusion 9 has added a new caching setting, Cache Template in Request, which is enabled by default. When enabled, this setting breaks event generation, as it causes the invocation of the newly-generated message-listener function in the controller CFC to fail with a method not found error.

This occurs because a controller CFC will be cached for the duration of the request, and controllers are instantiated before new functions are generated, thus causing an error when a newly-generated method is invoked.

In order to completely work around this problem, there are two requirements:

  1. The event generation pass would need to be moved before module loading in the framework's initialization process, and this would require a new method to test for the presence of an event-handler, as the generation controller presently uses getModelGlue().hasEventHandler() to check for an existing event, and this method will not work prior to module loading
  2. The controllerHasFunction() method in the XMLEventGenerationService CFC would need to be rewritten to avoid the use of the getMetadata() function, as this also causes a CFC to be cached in the request, as does the getComponentMetadata() function

An alternative approach was proposed on the MG mailing list by Elliott Sprehn -- he suggested redirecting back the the same event after the generation pass completes, thus circumventing the caching issue. This does indeed work to prevent the error from occurring, with the trade-offs being a bit of additional overhead from a second request, and the loss of the debugging information regarding the generated event.

Change History

Changed 16 years ago by cfgrok

I don't know that I'm sold on the redirection approach, but in case anyone wishes to try it out, here is the a modified version of the generateEvent() method of the generation controller that implements this solution:

<cffunction name="generateEvent" output="false" hint="If the requested event doesn't exist, I generate its XML as well as code stubs for a listener and a view.">
	<cfargument name="event" />
	
	<cfset var eventName = arguments.event.getValue(arguments.event.getValue("eventValue")) />
	
	<cfif not getModelGlue().hasEventHandler(eventName) and getModelGlue().getConfigSetting("generationEnabled")>
		<cfset beans.modelglueEventGenerator.generateEvent(arguments.event) />
		
		<cfset arguments.event.forward(eventName) />
	</cfif>
</cffunction>

Note: See TracTickets for help on using tickets.