<div dir="ltr">OK, here is some corrected code with some POD:<br><br>Index: PageCache.pm<br>===================================================================<br>--- PageCache.pm&nbsp;&nbsp;&nbsp; (revision 756)<br>+++ PageCache.pm&nbsp;&nbsp;&nbsp; (working copy)<br>
@@ -316,7 +316,9 @@<br>&nbsp;&nbsp;&nbsp;&nbsp; # use the key created during the initial dispatch phase<br>&nbsp;&nbsp;&nbsp;&nbsp; return $c-&gt;_page_cache_key if ( $c-&gt;_page_cache_key );<br>&nbsp;<br>-&nbsp;&nbsp;&nbsp; my $key = &quot;/&quot; . $c-&gt;req-&gt;path;<br>+&nbsp;&nbsp;&nbsp; # override key if required<br>
+&nbsp;&nbsp;&nbsp; my $keymaker = $c-&gt;config-&gt;{page_cache}-&gt;{key_maker};<br>+&nbsp;&nbsp;&nbsp; my $key = $keymaker ? $keymaker-&gt;($c) : &quot;/&quot; . $c-&gt;req-&gt;path;<br>&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp;&nbsp; # prepend language if I18N present.<br>&nbsp;&nbsp;&nbsp;&nbsp; if ( $c-&gt;can(&#39;language&#39;) ) {<br>
@@ -479,6 +481,17 @@<br>&nbsp;Note that this is called BEFORE auto_check_user, so you have more flexibility<br>&nbsp;to determine what to do for not logged in users.<br>&nbsp;<br>+To override the generation of page keys:<br>+<br>+__PACKAGE__-&gt;config(<br>
+&nbsp;&nbsp;&nbsp; page_cache =&gt; {<br>+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; key_maker =&gt; sub {<br>+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; my ($c) = @_;<br>+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return $c-&gt;req-&gt;base . &#39;/&#39; . $c-&gt;req-&gt;path;<br>+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>+&nbsp;&nbsp;&nbsp; }<br>+);<br>+<br>&nbsp;=head1 METHODS<br>
&nbsp;<br>&nbsp;=head2 cache_page<br><br><br>and here is a test:<br><br>#!perl<br><br>use strict;<br>use warnings;<br>no warnings &#39;redefine&#39;;<br><br>use FindBin;<br>use lib &quot;$FindBin::Bin/lib&quot;;<br>use Test::More;<br>
use File::Path;<br><br>BEGIN {<br>&nbsp;&nbsp;&nbsp; eval &quot;use Catalyst::Plugin::Cache::FileCache&quot;;<br>&nbsp;&nbsp;&nbsp; plan $@<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ? ( skip_all =&gt; &#39;needs Catalyst::Plugin::Cache::FileCache for testing&#39; )<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : ( tests =&gt; 8 );<br>
}<br><br># This test that options can be passed to cache.<br><br># remove previous cache<br>rmtree &#39;t/var&#39; if -d &#39;t/var&#39;;<br><br>use Catalyst::Test &#39;TestApp&#39;;<br><br># add config option<br>TestApp-&gt;config-&gt;{page_cache}-&gt;{key_maker} = sub {<br>
&nbsp;&nbsp;&nbsp; my ($c) = @_;<br>&nbsp;&nbsp;&nbsp; return $c-&gt;req-&gt;base . q{/} . $c-&gt;req-&gt;path;<br>};<br><br># cache a page<br>ok( my $res = request(&#39;<a href="http://host1/cache/count&#39;">http://host1/cache/count&#39;</a>), &#39;request ok&#39; );<br>
is( $res-&gt;content, 1, &#39;count is 1&#39; );<br><br># page will be served from cache<br>ok( $res = request(&#39;<a href="http://host1/cache/count&#39;">http://host1/cache/count&#39;</a>), &#39;request ok&#39; );<br>is( $res-&gt;content, 1, &#39;count is still 1 from cache&#39; );<br>
<br># page will not be served from cache<br>ok( $res = request(&#39;<a href="http://host2/cache/count&#39;">http://host2/cache/count&#39;</a>), &#39;request ok&#39; );<br>is( $res-&gt;content, 2, &#39;count is 2 from cache&#39; );<br>
<br># page will be served from cache<br>ok( $res = request(&#39;<a href="http://host2/cache/count&#39;">http://host2/cache/count&#39;</a>), &#39;request ok&#39; );<br>is( $res-&gt;content, 2, &#39;count is still 2 from cache&#39; );<br>
<br><div class="gmail_quote">2008/8/9 Martin Ellison <span dir="ltr">&lt;<a href="mailto:m.e@acm.org">m.e@acm.org</a>&gt;</span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div dir="ltr">What about:... [bad code]...<br><br>What else do you need? POD? Tests?<br>
<br><div class="gmail_quote">2008/8/9 Martin Ellison <span dir="ltr">&lt;<a href="mailto:m.e@acm.org" target="_blank">m.e@acm.org</a>&gt;</span><div><div></div><div class="Wj3C7c"><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

<div dir="ltr">I&#39;m concerned about impacting the performance; this must be high-traffic code. But I&#39;ll look into it.<br><br><div class="gmail_quote">2008/8/8 Matt S Trout <span dir="ltr">&lt;<a href="mailto:dbix-class@trout.me.uk" target="_blank">dbix-class@trout.me.uk</a>&gt;</span><div>

<div></div><div><br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div>On Fri, Aug 08, 2008 at 05:08:02PM +0800, Martin Ellison wrote:<br>
&gt; But PageCache only works off $c-&gt;request-&gt;path() ie not the hostname. This<br>
&gt; behaviour is coded in the _get_page_cache_key() subroutine. This means that<br>
&gt; the PageCache serves up the same page content for all websites, irrespective<br>
&gt; of URL, which is not what I want.<br>
&gt;<br>
&gt; It would be nice if there were some way to fix this and keep using<br>
&gt; PageCache, such as overriding _get_page_cache_key(). Does that make sense?<br>
&gt; eg writing a derived class from PageCache?<br>
<br>
</div>How about<br>
<br>
__PACKAGE__-&gt;config(<br>
 &nbsp;&#39;Plugin::PageCache&#39; =&gt; {<br>
 &nbsp; &nbsp;key_maker =&gt; sub {<br>
 &nbsp; &nbsp; &nbsp;my $c = shift;<br>
 &nbsp; &nbsp; &nbsp;handwave($c);<br>
 &nbsp; &nbsp;}<br>
 &nbsp;}<br>
);<br>
<br>
and making the current implementation the default in the absence thereof?<br>
<br>
Fancy having a play with doing a patch?<br>
<br></blockquote></div></div></div></div></blockquote></div></div></div></div></blockquote></div><br clear="all"><br>-- <br>Regards,<br>Martin<br>(<a href="mailto:m.e@acm.org">m.e@acm.org</a>)<br>IT: <a href="http://methodsupport.com">http://methodsupport.com</a> Personal: <a href="http://thereisnoend.org">http://thereisnoend.org</a><br>

</div>