I put up the patch several days ago; has anyone looked at it?

2008/8/9 Martin Ellison <[EMAIL PROTECTED]>

> OK, here is some corrected code with some POD:
>
> Index: PageCache.pm
> ===================================================================
> --- PageCache.pm    (revision 756)
> +++ PageCache.pm    (working copy)
> @@ -316,7 +316,9 @@
>      # use the key created during the initial dispatch phase
>      return $c->_page_cache_key if ( $c->_page_cache_key );
>
> -    my $key = "/" . $c->req->path;
> +    # override key if required
> +    my $keymaker = $c->config->{page_cache}->{key_maker};
> +    my $key = $keymaker ? $keymaker->($c) : "/" . $c->req->path;
>
>      # prepend language if I18N present.
>      if ( $c->can('language') ) {
> @@ -479,6 +481,17 @@
>  Note that this is called BEFORE auto_check_user, so you have more
> flexibility
>  to determine what to do for not logged in users.
>
> +To override the generation of page keys:
> +
> +__PACKAGE__->config(
> +    page_cache => {
> +        key_maker => sub {
> +            my ($c) = @_;
> +            return $c->req->base . '/' . $c->req->path;
> +          }
> +    }
> +);
> +
>  =head1 METHODS
>
>  =head2 cache_page
>
>
> and here is a test:
>
> #!perl
>
> use strict;
> use warnings;
> no warnings 'redefine';
>
> use FindBin;
> use lib "$FindBin::Bin/lib";
> use Test::More;
> use File::Path;
>
> BEGIN {
>     eval "use Catalyst::Plugin::Cache::FileCache";
>     plan $@
>       ? ( skip_all => 'needs Catalyst::Plugin::Cache::FileCache for
> testing' )
>       : ( tests => 8 );
> }
>
> # This test that options can be passed to cache.
>
> # remove previous cache
> rmtree 't/var' if -d 't/var';
>
> use Catalyst::Test 'TestApp';
>
> # add config option
> TestApp->config->{page_cache}->{key_maker} = sub {
>     my ($c) = @_;
>     return $c->req->base . q{/} . $c->req->path;
> };
>
> # cache a page
> ok( my $res = 
> request('http://host1/cache/count'<http://host1/cache/count%27>),
> 'request ok' );
> is( $res->content, 1, 'count is 1' );
>
> # page will be served from cache
> ok( $res = request('http://host1/cache/count'<http://host1/cache/count%27>),
> 'request ok' );
> is( $res->content, 1, 'count is still 1 from cache' );
>
> # page will not be served from cache
> ok( $res = request('http://host2/cache/count'<http://host2/cache/count%27>),
> 'request ok' );
> is( $res->content, 2, 'count is 2 from cache' );
>
> # page will be served from cache
> ok( $res = request('http://host2/cache/count'<http://host2/cache/count%27>),
> 'request ok' );
> is( $res->content, 2, 'count is still 2 from cache' );
>
> 2008/8/9 Martin Ellison <[EMAIL PROTECTED]>
>
>> What about:... [bad code]...
>>
>> What else do you need? POD? Tests?
>>
>> 2008/8/9 Martin Ellison <[EMAIL PROTECTED]>
>>
>> I'm concerned about impacting the performance; this must be high-traffic
>>> code. But I'll look into it.
>>>
>>> 2008/8/8 Matt S Trout <[EMAIL PROTECTED]>
>>>
>>> On Fri, Aug 08, 2008 at 05:08:02PM +0800, Martin Ellison wrote:
>>>> > But PageCache only works off $c->request->path() ie not the hostname.
>>>> This
>>>> > behaviour is coded in the _get_page_cache_key() subroutine. This means
>>>> that
>>>> > the PageCache serves up the same page content for all websites,
>>>> irrespective
>>>> > of URL, which is not what I want.
>>>> >
>>>> > It would be nice if there were some way to fix this and keep using
>>>> > PageCache, such as overriding _get_page_cache_key(). Does that make
>>>> sense?
>>>> > eg writing a derived class from PageCache?
>>>>
>>>> How about
>>>>
>>>> __PACKAGE__->config(
>>>>  'Plugin::PageCache' => {
>>>>    key_maker => sub {
>>>>      my $c = shift;
>>>>      handwave($c);
>>>>    }
>>>>  }
>>>> );
>>>>
>>>> and making the current implementation the default in the absence
>>>> thereof?
>>>>
>>>> Fancy having a play with doing a patch?
>>>>
>>>>
>
> --
> Regards,
> Martin
> ([EMAIL PROTECTED])
> IT: http://methodsupport.com Personal: http://thereisnoend.org
>



-- 
Regards,
Martin
([EMAIL PROTECTED])
IT: http://methodsupport.com Personal: http://thereisnoend.org
_______________________________________________
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/

Reply via email to