<div dir="ltr">OK, here is some corrected code with some POD:<br><br>Index: PageCache.pm<br>===================================================================<br>--- PageCache.pm (revision 756)<br>+++ PageCache.pm (working copy)<br>
@@ -316,7 +316,9 @@<br> # use the key created during the initial dispatch phase<br> return $c->_page_cache_key if ( $c->_page_cache_key );<br> <br>- my $key = "/" . $c->req->path;<br>+ # override key if required<br>
+ my $keymaker = $c->config->{page_cache}->{key_maker};<br>+ my $key = $keymaker ? $keymaker->($c) : "/" . $c->req->path;<br> <br> # prepend language if I18N present.<br> if ( $c->can('language') ) {<br>
@@ -479,6 +481,17 @@<br> Note that this is called BEFORE auto_check_user, so you have more flexibility<br> to determine what to do for not logged in users.<br> <br>+To override the generation of page keys:<br>+<br>+__PACKAGE__->config(<br>
+ page_cache => {<br>+ key_maker => sub {<br>+ my ($c) = @_;<br>+ return $c->req->base . '/' . $c->req->path;<br>+ }<br>+ }<br>+);<br>+<br> =head1 METHODS<br>
<br> =head2 cache_page<br><br><br>and here is a test:<br><br>#!perl<br><br>use strict;<br>use warnings;<br>no warnings 'redefine';<br><br>use FindBin;<br>use lib "$FindBin::Bin/lib";<br>use Test::More;<br>
use File::Path;<br><br>BEGIN {<br> eval "use Catalyst::Plugin::Cache::FileCache";<br> plan $@<br> ? ( skip_all => 'needs Catalyst::Plugin::Cache::FileCache for testing' )<br> : ( tests => 8 );<br>
}<br><br># This test that options can be passed to cache.<br><br># remove previous cache<br>rmtree 't/var' if -d 't/var';<br><br>use Catalyst::Test 'TestApp';<br><br># add config option<br>TestApp->config->{page_cache}->{key_maker} = sub {<br>
my ($c) = @_;<br> return $c->req->base . q{/} . $c->req->path;<br>};<br><br># cache a page<br>ok( my $res = request('<a href="http://host1/cache/count'">http://host1/cache/count'</a>), 'request ok' );<br>
is( $res->content, 1, 'count is 1' );<br><br># page will be served from cache<br>ok( $res = request('<a href="http://host1/cache/count'">http://host1/cache/count'</a>), 'request ok' );<br>is( $res->content, 1, 'count is still 1 from cache' );<br>
<br># page will not be served from cache<br>ok( $res = request('<a href="http://host2/cache/count'">http://host2/cache/count'</a>), 'request ok' );<br>is( $res->content, 2, 'count is 2 from cache' );<br>
<br># page will be served from cache<br>ok( $res = request('<a href="http://host2/cache/count'">http://host2/cache/count'</a>), 'request ok' );<br>is( $res->content, 2, 'count is still 2 from cache' );<br>
<br><div class="gmail_quote">2008/8/9 Martin Ellison <span dir="ltr"><<a href="mailto:m.e@acm.org">m.e@acm.org</a>></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"><<a href="mailto:m.e@acm.org" target="_blank">m.e@acm.org</a>></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'm concerned about impacting the performance; this must be high-traffic code. But I'll look into it.<br><br><div class="gmail_quote">2008/8/8 Matt S Trout <span dir="ltr"><<a href="mailto:dbix-class@trout.me.uk" target="_blank">dbix-class@trout.me.uk</a>></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>
> But PageCache only works off $c->request->path() ie not the hostname. This<br>
> behaviour is coded in the _get_page_cache_key() subroutine. This means that<br>
> the PageCache serves up the same page content for all websites, irrespective<br>
> of URL, which is not what I want.<br>
><br>
> It would be nice if there were some way to fix this and keep using<br>
> PageCache, such as overriding _get_page_cache_key(). Does that make sense?<br>
> eg writing a derived class from PageCache?<br>
<br>
</div>How about<br>
<br>
__PACKAGE__->config(<br>
'Plugin::PageCache' => {<br>
key_maker => sub {<br>
my $c = shift;<br>
handwave($c);<br>
}<br>
}<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>