FAQ
I get the impression that PageCache cannot discriminate on URL; is that
correct?

I am trying to 'whitelabel' a site, that is to run several hostnames into
the one Catalyst site and then serve somewhat different content based on the
URL, giving the appearance of multiple websites. However, it seems that the
PageCache plugin does not allow this.

For example, I might have two hostnames:

- http://www.example1.com and
- http://www.example2.net

that both point to the same Catalyst server. I can find out the URL using
$c->request->base() and use that to, say, select the appropriate CSS file
and heading template for that site.

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?

--
Regards,
Martin
(m.e@acm.org)
IT: http://methodsupport.com Personal: http://thereisnoend.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20080808/c297a0eb/attachment.htm

Search Discussions

  • Martin Ellison at Aug 8, 2008 at 12:34 pm
    I have tried subclassing PageCache, but it is not doing Catalyst magic: when
    asked to do

    * $c->cache_page( ..)

    it says *

    Can't locate object method "cache_page" via package....



    2008/8/8 Martin Ellison <m.e@acm.org>
    I get the impression that PageCache cannot discriminate on URL; is that
    correct?

    I am trying to 'whitelabel' a site, that is to run several hostnames into
    the one Catalyst site and then serve somewhat different content based on the
    URL, giving the appearance of multiple websites. However, it seems that the
    PageCache plugin does not allow this.

    For example, I might have two hostnames:

    - http://www.example1.com and
    - http://www.example2.net

    that both point to the same Catalyst server. I can find out the URL using
    $c->request->base() and use that to, say, select the appropriate CSS file
    and heading template for that site.

    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?

    --
    Regards,
    Martin
    (m.e@acm.org)
    IT: http://methodsupport.com Personal: http://thereisnoend.org


    --
    Regards,
    Martin
    (m.e@acm.org)
    IT: http://methodsupport.com Personal: http://thereisnoend.org
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20080808/27ac508f/attachment.htm
  • Matt S Trout at Aug 8, 2008 at 3:19 pm

    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?

    --
    Matt S Trout Need help with your Catalyst or DBIx::Class project?
    Technical Director http://www.shadowcat.co.uk/catalyst/
    Shadowcat Systems Ltd. Want a managed development or deployment platform?
    http://chainsawblues.vox.com/ http://www.shadowcat.co.uk/servers/
  • Martin Ellison at Aug 8, 2008 at 5:29 pm
    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 <dbix-class@trout.me.uk>
    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?

    --
    Matt S Trout Need help with your Catalyst or DBIx::Class
    project?
    Technical Director
    http://www.shadowcat.co.uk/catalyst/
    Shadowcat Systems Ltd. Want a managed development or deployment platform?
    http://chainsawblues.vox.com/
    http://www.shadowcat.co.uk/servers/

    _______________________________________________
    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/


    --
    Regards,
    Martin
    (m.e@acm.org)
    IT: http://methodsupport.com Personal: http://thereisnoend.org
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20080809/eac04381/attachment.htm
  • Martin Ellison at Aug 9, 2008 at 6:59 am
    What about:

    @@ -316,7 +317,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;

    What else do you need? POD? Tests?

    2008/8/9 Martin Ellison <m.e@acm.org>
    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 <dbix-class@trout.me.uk>
    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?

    --
    Matt S Trout Need help with your Catalyst or DBIx::Class
    project?
    Technical Director
    http://www.shadowcat.co.uk/catalyst/
    Shadowcat Systems Ltd. Want a managed development or deployment
    platform?
    http://chainsawblues.vox.com/
    http://www.shadowcat.co.uk/servers/

    _______________________________________________
    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/


    --
    Regards,
    Martin
    (m.e@acm.org)
    IT: http://methodsupport.com Personal: http://thereisnoend.org


    --
    Regards,
    Martin
    (m.e@acm.org)
    IT: http://methodsupport.com Personal: http://thereisnoend.org
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20080809/45ad9b6a/attachment.htm
  • Martin Ellison at Aug 9, 2008 at 8:43 am
    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'), 'request ok' );
    is( $res->content, 1, 'count is 1' );

    # page will be served from cache
    ok( $res = request('http://host1/cache/count'), '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'), 'request ok' );
    is( $res->content, 2, 'count is 2 from cache' );

    # page will be served from cache
    ok( $res = request('http://host2/cache/count'), 'request ok' );
    is( $res->content, 2, 'count is still 2 from cache' );

    2008/8/9 Martin Ellison <m.e@acm.org>
    What about:... [bad code]...

    What else do you need? POD? Tests?

    2008/8/9 Martin Ellison <m.e@acm.org>

    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 <dbix-class@trout.me.uk>
    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
    (m.e@acm.org)
    IT: http://methodsupport.com Personal: http://thereisnoend.org
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20080809/45d99bc2/attachment.htm
  • Martin Ellison at Aug 13, 2008 at 7:59 am
    I put up the patch several days ago; has anyone looked at it?

    2008/8/9 Martin Ellison <m.e@acm.org>
    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 <m.e@acm.org>
    What about:... [bad code]...

    What else do you need? POD? Tests?

    2008/8/9 Martin Ellison <m.e@acm.org>

    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 <dbix-class@trout.me.uk>
    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
    (m.e@acm.org)
    IT: http://methodsupport.com Personal: http://thereisnoend.org


    --
    Regards,
    Martin
    (m.e@acm.org)
    IT: http://methodsupport.com Personal: http://thereisnoend.org
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20080813/e402fdbd/attachment.htm
  • Matt S Trout at Aug 17, 2008 at 6:42 pm

    On Wed, Aug 13, 2008 at 02:59:24PM +0800, Martin Ellison wrote:
    I put up the patch several days ago; has anyone looked at it?
    Start a thread on catalyst-dev indicating it's got a patch attached if you
    want the maintainer to spot it.

    Also, config should be under 'Plugin::PageCache' as I said - that's the
    standard for plugin config info.

    If PageCache is still using old style it'd be nice if you could do a first
    patch switching it across.

    --
    Matt S Trout Need help with your Catalyst or DBIx::Class project?
    Technical Director http://www.shadowcat.co.uk/catalyst/
    Shadowcat Systems Ltd. Want a managed development or deployment platform?
    http://chainsawblues.vox.com/ http://www.shadowcat.co.uk/servers/
  • Martin Ellison at Aug 18, 2008 at 5:37 am
    2008/8/18 Matt S Trout <dbix-class@trout.me.uk>
    ...config should be under 'Plugin::PageCache' as I said - that's the
    standard for plugin config info.

    If PageCache is still using old style it'd be nice if you could do a first
    patch switching it across.
    I'm concerned about doing two things in the one patch; can we do my patch
    first?

    --
    Regards,
    Martin
    (m.e@acm.org)
    IT: http://methodsupport.com Personal: http://thereisnoend.org
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20080818/76c3fa66/attachment.htm
  • Matt S Trout at Aug 18, 2008 at 10:49 am

    On Mon, Aug 18, 2008 at 12:37:11PM +0800, Martin Ellison wrote:
    2008/8/18 Matt S Trout <dbix-class@trout.me.uk>
    ...config should be under 'Plugin::PageCache' as I said - that's the
    standard for plugin config info.

    If PageCache is still using old style it'd be nice if you could do a first
    patch switching it across.
    I'm concerned about doing two things in the one patch; can we do my patch
    first?
    That's why I said "first patch", with the one adding functionality coming
    after the one that fixes it up to modern standard.

    --
    Matt S Trout Need help with your Catalyst or DBIx::Class project?
    Technical Director http://www.shadowcat.co.uk/catalyst/
    Shadowcat Systems Ltd. Want a managed development or deployment platform?
    http://chainsawblues.vox.com/ http://www.shadowcat.co.uk/servers/

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupcatalyst @
categoriescatalyst, perl
postedAug 8, '08 at 10:08a
activeAug 18, '08 at 10:49a
posts10
users2
websitecatalystframework.org
irc#catalyst

2 users in discussion

Martin Ellison: 7 posts Matt S Trout: 3 posts

People

Translate

site design / logo © 2021 Grokbase