Mojolic...in::CHI(3)
π Mojolic...in::CHI β the manual, but make it a group chat π
okay bestie so you're holding the manual page for Mojolic...in::CHI(3) β yeah the name got elbowed in the middle like that, it's from the User Contributed Perl Documentation collection, and it's literally all about using CHI caches inside Mojolicious. sit down, hydrate, we're doing this π«Ά
β¨ NAME β¨
Mojolicious::Plugin::CHI β Use CHI Caches in Mojolicious
it's giving "plug your cache into your app and never think about it again." iconic behavior, no cap.
πΈ SYNOPSIS πΈ
# 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');
see how easy that was?? one plugin call, a lil hash of caches, and boom π
π¦ DESCRIPTION π¦
Mojolicious::Plugin::CHI is a simple plugin to work with CHI caches within Mojolicious.
that's it. that's the description. simple girl, big dreams π
π METHODS π
π 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
}
}
}
okay so this is the one that runs when the plugin gets registered. π when it's created, the plugin takes a hash of cache names, each one paired up with CHI objects. all cache handles are qualified CHI namespaces. if you're not feeling that mapping, you can leave it out entirely by passing a namespaces parameter with a false value. and heads up bestie β the handles have to be unique, like, you literally can't have multiple different default caches in mounted applications using Mojolicious::Plugin::Mount. no duplicates allowed, that's the rule π’
logging? it defaults to the application log, but you can override that with on_get_error and on_set_error. cute.
every parameter can be set as part of the configuration file under the key CHI, or on registration β and btw registration values can be overwritten by configuration. so config wins. queen behavior π
want custom CHI subclasses? pass a chi_class parameter with the class name of a CHI subclass. slay β¨
π HELPERS π
π 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. it accepts the name of the registered cache. and if you don't hand it a cache handle name at all? it just assumes default. she's low maintenance like that π
π COMMANDS π
these are the commands you get when the plugin is registered. all of them are run through your app like perl app.pl <stuff>, okurrr? π
β chi list
perl app.pl chi list
List all CHI caches associated with your application.
π chi purge
perl app.pl chi purge mycache
Remove all expired entries from the cache namespace. expired content, gone, bye π
π§ chi clear
perl app.pl chi clear mycache
Remove all entries from the cache namespace. all of them. full reset energy π
π chi expire
perl app.pl chi expire mykey
perl app.pl chi expire mycache mykey
Set the expiration date of a key to the past. it does not necessarily delete the data β it just makes it unavailable using get. so the data's still lurking backstage, just not answering calls anymore π
π chi remove
perl app.pl chi remove mykey
perl app.pl chi remove mycache mykey
Remove a key from the cache. actually gone. periodt.
π«Ά DEPENDENCIES π«Ά
Mojolicious, CHI.
Note: old versions of CHI had a lot of dependencies. because of that, it was not recommended to use this plugin in a CGI environment. since new versions of CHI use Moo instead of Moose, more use cases may be possible. glow-up fr fr β¨
πΈ CONTRIBUTORS πΈ
- Boris DΓ€ppen <https://github.com/borisdaeppen>
- RenΓ©e BΓ€cker <https://github.com/reneeb>
- Rouzier <https://github.com/rouzier>
- Mohammad S Anwar <https://github.com/manwar>
the girlies who made it happen π
π AVAILABILITY π
https://github.com/Akron/Mojolicious-Plugin-CHI
go star it, bestie β
π COPYRIGHT AND LICENSE π
Copyright (C) 2012-2018, Nils Diewald <http://nils-diewald.de/>.
This program is free software, you can redistribute it and/or modify it under the terms of the Artistic License version 2.0.
and that's the whole manual, bestie!! this page came to you from perl v5.42.0, dated 2025-07-25, and it's filed under that slightly chopped-up title Mojolic...in::CHI(3) π go forth and cache responsibly, mwah π«Άβ¨
π¦ where this page comes from
- fedora 43: perl-Mojolicious-Plugin-CHI 0.20-21.fc43 Β· Artistic-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms