[Zope-CMF] Re: CachingPolicyManager

Miles Waller miles at jamkit.com
Wed Oct 11 15:20:25 EDT 2006


>> My question is, does this count as a bug?
> 
> 
> I'm not sure this can be called a bug. It is true (and perfectly  
> normal) that rendering a filesystem page template will always call  the 
> CPM. You're rendering both here. Since output_page_2 is rendered  last 
> as it's calles from output_page_1 the rule for output_page_2  fires and 
> will overwrite existing headers/add new headers according  to the rule 
> that fires. 

That's got me thinking of some more potential examples of 'odd' behaviour:

(a) output_page_1 and output_page_2 both have rules associated that 
apply the same headers (but different values):
the output will have the expected headers because output_page_1's rule 
will fire last of all, overwriting the headers applied by output_page_2

(b) output_page_1 and output_page_2 both have rules associated applying 
different headers:
the output will be a mix of the headers applied by both rules, with 
those applied due to output_page_1 taking precedence.

(c) only output_page_2 has a rule associated with it:
the output will contain headers applied due to output_page_2's rules, 
whereas no headers are expected.

B and C are particularly frustrating, as there is no way to set a rule 
that will remove the headers added by any other rule that might have 
been fired previously.  B seems particularly confusing to me (I am glad 
it did not come up or I would still be investigating!).  There might be 
even more confusing interactions where 304s are enabled on some rules 
but not others...

 > The problem here is that both happen in the  same request,
> the rendering code does not distinguish betwen the primary and the 
> nested rendering.

That's what I think the bug is: it should distinguish.

I've fixed it locally for me as follows:

  - when a FSZPT is called, it looks for a request attribute (called 
'template_count' or somesuch)
  - if the attribute is present (i.e. it's a "subtemplate"), it adds one 
to the value
  - otherwise, it sets it to zero
  - it carries on as normal to generate some output
  - the request attribute is decreased
  - the cpm is only called if the attribute is zero, as this indicates 
the item is no longer a "subtemplate"

This works fine to suppress use of the cpm by any nested rendering. 
Does it seem like a reasonable solution or is there a better way of 
achieving the same thing?  I cannot think of any simpler way of 
detecting whether an item is the 'original' template or a 'subtemplate'

Miles



More information about the Zope-CMF mailing list