NAME
MojoX::Renderer::Cache - Cache rendered output in Mojo
SYNOPSIS
Add the handler:
use MojoX::Renderer::TT;
use MojoX::Renderer::Cache;
use Cache::File;
sub startup {
...
my $tt = MojoX::Renderer::TT->build(
mojo => $self,
template_options =>
{ PROCESS => 'tpl/wrapper',
FILTERS => [ foo => [ \&filter_factory, 1]
}
);
my $cache = MojoX::Renderer::Cache->build(
renderer => $tt,
key => [qw(template_path article)],
cache => Cache::File->new(
cache_root => '/tmp',
default_expires => '5 minutes',
),
);
$self->renderer->add_handler( tt => $cache );
And then in the handler call render which will call the MojoX::Renderer::Cache renderer. This will either call the given renderer or use a cached version of the output:
$c->render(foo => 123, bar => [qw(giz mo)]);
STASH VARIABLES
- uncached (1|0)
-
You can force rendering by setting the stash variable
uncachedto a true value (this will also not add the rendered page to the cache). - cache_expires VALUE
-
By setting the stash variable
cache_expires, you can change the default expire time of the cache object. Setting this, will write to the cache, no matter ifuncached(see above) was true or not. See Cache on what vaild values for VALUE are.
METHODS
build
This method returns a handler for the Mojo renderer.
Supported parameters are
- renderer
-
This must be a valid Mojo renderer, which will be used to render the output if a page is not in the cache. No defaults, this is a required option.
- cache
-
This must be a Cache::* object which uses the same API as Cache / Cache::File (most important, it requires a
get()and aset()method which act likeCache::*). No defaults, this is a required option. - key
-
A list of stash variables which will be used to construct a unique key for the given page. Default is
qw{ template_path }
SEE ALSO
Cache, Cache::File, Cache::Memory, MojoX::Renderer
AUTHOR
Hanno Hecker <vetinari@ankh-morp.org>
COPYRIGHT & LICENSE
Copyright 2009 Hanno Hecker, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.




