Mojolicious::Plugin::CHI - Use CHI caches within Mojolicious
# Mojolicious $app->plugin(CHI => { MyCache => { driver => 'FastMmap', root_dir => '/cache', cache_size => '20m' } }); # Mojolicious::Lite plugin 'CHI' => { default => { driver => 'Memory', global => 1 } }; # In Controllers: $c->chi('MyCache')->set(my_key => 'This is my value'); print $c->chi('MyCache')->get('my_key'); # Using the default cache $c->chi->set(from_memory => 'With love!'); print $c->chi->get('from_memory');
Mojolicious::Plugin::CHI is a simple plugin to work with CHI caches within Mojolicious.
register
# Mojolicious $app->plugin(CHI => { MyCache => { driver => 'FastMmap', root_dir => '/cache', cache_size => '20m' }, default => { driver => 'Memory', global => 1 }, namespaces => 1 }); # Mojolicious::Lite plugin 'CHI' => { default => { driver => 'Memory', global => 1 } }; # Or in your config file { CHI => { default => { driver => 'Memory', global => 1 } } }
Called when registering the plugin. On creation, the plugin accepts a hash of cache names associated with CHI objects. In addition to that, you can make all cache handles qualified CHI namespaces by setting the namespaces parameter to a true value.
namespaces
All parameters can be set either on registration or as part of the configuration file with the key CHI.
CHI
Note: Currently, the namespaces flag is off by default and cache handles are independent from namespaces. This will change in an upcoming release. To prevent cache rebuilding in the future, set namespaces to a true value.
chi
# In Controllers: $c->chi('MyCache')->set(my_key => 'This is my value', '10 min'); print $c->chi('MyCache')->get('my_key'); print $c->chi->get('from_default_cache');
Returns a CHI handle if registered. Accepts the name of the registered cache. If no cache handle name is given, a cache handle name default is assumed.
default
Mojolicious, CHI.
Note: CHI has a lot of dependencies. It is thus not recommended to use this plugin in a CGI environment.
Boris Däppen (borisdaeppen)
reneeb
https://github.com/Akron/Mojolicious-Plugin-CHI
Copyright (C) 2012, Nils Diewald.
This program is free software, you can redistribute it and/or modify it under the same terms as Perl.
To install Mojolicious::Plugin::CHI, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Mojolicious::Plugin::CHI
CPAN shell
perl -MCPAN -e shell install Mojolicious::Plugin::CHI
For more information on module installation, please visit the detailed CPAN module installation guide.