FAQ
Hello All,

I have a trouble about PageCache(Cache::FileCache) and SubRequest .
The part using SubRequest of the page cannot be cached often .

- Controller :
use Catalyst qw/SubRequest Cache::FileCache PageCache/;

__PACKAGE__->config->{page_cache} = {
expires => 300,
set_http_headers => 1,
debug => 1,
};
__PACKAGE__->config->{cache}->{storage} = '/tmp';

sub index : Local {
my ( $self, $c ) = @_;
$c->cache_page( 300 );
# action
$c->stash->{template} = 'index.tt'
$c->forward("My::View::TT");
}

sub test : Path('/parts/test') {
my ( $self, $c ) = @_;
$c->response->body('Test');
}

- TT (index.tt):
<html>
<body>
Hello
[%c.subreq('/parts/test')%]
</body>
</html>

I hope that the page including 'Hello' and 'Test' are cached.
But, often I cannot see 'Test' in the cached page.
The behavior often happens.

Best regards,
---
Kyoko Shikamata

Search Discussions

  • Peter Karman at Nov 20, 2007 at 2:32 pm

    On 11/20/2007 04:39 AM, Kyoko Shikamata wrote:
    Hello All,

    I have a trouble about PageCache(Cache::FileCache) and SubRequest .
    The part using SubRequest of the page cannot be cached often .

    - Controller :
    use Catalyst qw/SubRequest Cache::FileCache PageCache/;

    __PACKAGE__->config->{page_cache} = {
    expires => 300,
    set_http_headers => 1,
    debug => 1,
    };
    __PACKAGE__->config->{cache}->{storage} = '/tmp';

    sub index : Local {
    my ( $self, $c ) = @_;
    $c->cache_page( 300 );
    # action
    $c->stash->{template} = 'index.tt'
    $c->forward("My::View::TT");
    }

    sub test : Path('/parts/test') {
    my ( $self, $c ) = @_;
    $c->response->body('Test');
    }

    - TT (index.tt):
    <html>
    <body>
    Hello
    [%c.subreq('/parts/test')%]
    </body>
    </html>

    I hope that the page including 'Hello' and 'Test' are cached.
    But, often I cannot see 'Test' in the cached page.
    The behavior often happens.
    You likely need to cache the page (or parts of it) instead of the request. See
    Template::Plugin::Cache and use the existing cache object. I have code using
    that technique in production, for caching parts of pages, and it works wonderfully.
    --
    Peter Karman . peter@peknet.com . http://peknet.com/

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupcatalyst @
categoriescatalyst, perl
postedNov 20, '07 at 10:39a
activeNov 20, '07 at 2:32p
posts2
users2
websitecatalystframework.org
irc#catalyst

2 users in discussion

Kyoko Shikamata: 1 post Peter Karman: 1 post

People

Translate

site design / logo © 2021 Grokbase