[Catalyst] PageCache and SubRequest

Peter Karman peter at peknet.com
Tue Nov 20 14:32:49 GMT 2007



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 at peknet.com  .  http://peknet.com/




More information about the Catalyst mailing list