[Catalyst] Partial page cache plugin

Julien Sobrier julien at sobrier.net
Sun Dec 6 22:50:59 GMT 2009


Thank you, I will lokk in this direction.

Julien

On Sun, Dec 6, 2009 at 2:56 AM, Octavian R=E2snita <orasnita at gmail.com> wro=
te:

> From: "Julien Sobrier" <julien at sobrier.net>
>
>  Hello,
>> there is a plugin for caching an entire page.  I am looking for the same
>> type of plugin to cache part of the page, but did not find one. Waht is
>> the
>> best way to achieve this in Catalyst?
>>
>
> You can use Catalyst::Plugin::Cache. You can do:
>
> use Digest::SHA1 'sha1_hex';
> use base 'Catalyst::Controller';
>
> sub foo : Local {
>  my ($self, $c) =3D @_;
>
> my $name =3D $c->req->params->{name};
> my $age =3D $c->req->params->{age};
> my $page =3D $c->req->params->{page};
>
>  my $hash =3D sha1_hex('foo', $name, $age, $page);
>  my $cache =3D $c->cache;
>  my $page_part =3D $cache->get($hash);
>
> unless ($page_part) {
> #Here make the selection from the database, get the data from somewhere
> else...
> my $object =3D $c->model("DB::Table")->search({
> name =3D> {-like =3D> "%$name%"},
> age =3D> $age,
> },{
> order_by =3D> 'name',
> rows =3D> 20,
> page =3D> $page,
> });
>
> $c->stash(obj =3D> $obj);
> $page_part =3D $c->view('TT')->render($c, 'template/for/that/part/of/the/
> page.tt');
>
> $cache->set($hash, $page_part, 600);
> }
>
> $c->stash(page_part =3D> $page_part);
> }
>
> This way it works fine, although if someone has an easier and/or nicer
> solution, please tell us.
>
> PageCache has some conflicts with another plugin, if I remember well is
> Catalyst::Plugin::Unicode.
>
> Template::Plugin::Cache that can be used for page parts caching very easy
> doesn't work well with templates that contain special UTF-8 chars (I was
> informed that this is because the FileCache module and I heard that it co=
uld
> work with a CHI object).
>
> Anyway, if somebody has some recommendations for speed improvements with
> Catalyst, please tell us if there are (I have checked a PHP page with many
> dynamic types of data that have a 44 requests/second, but I wasn't able to
> create a much simpler page with Catalyst that displays so fast).
> Yes, I know, the PHP page is low level, harder to create and to maintain,
> gives bad errors, but I can't convince that Catalyst is good if it is not
> fast enough, so any tips for using caches or other ways of improving the
> speed are welcome.
>
> Thank you.
>
> Octavian
>
>
>
> _______________________________________________
> List: Catalyst at 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/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20091206/0eb11=
949/attachment.htm


More information about the Catalyst mailing list