Mason:...:Cache(3pm)
π Mason::Plugin::Cache π
okay so bestie, this is a page from the User Contributed Perl Documentation section of the manual β the Mason:...:Cache(3pm) one, iykyk β and it's literally just here to teach you how to cache stuff in Mason. Sit down, hydrate, let's go π
β¨ NAME β¨
Mason::Plugin::Cache β it hands you a component cache object and a filter, no cap π«Ά
πΈ VERSION πΈ
version 0.05
π¦ SYNOPSIS π¦
the vibe check, in code:
my $result = $.cache->get('key');
if (!defined($result)) {
... compute $result ...
$.cache->set('key', $result, '5 minutes');
}
...
% $.Cache('key2', '1 hour') {{
<!-- this will be cached for an hour -->
% }}
π DESCRIPTION π
It adds a "cache" method and a "Cache" filter so you can reach a cache (CHI) object. And the iconic part? That cache object gets a namespace that's unique to the component. main character energy fr β¨
π INTERP PARAMETERS π
cache_defaults
A hash of parameters that get passed to the cache constructor. Defaults to
driver=>'File', root_dir => 'DATA_DIR/cache'
which lowkey just makes a basic file cache sitting under Mason's data directory. cute, simple, slays π
cache_root_class
The class used to create a cache. Defaults to CHI.
π COMPONENT CLASS METHODS π
cache
Returns a new cache object, with the namespace set to the component's path. Any parameters you hand this method get combined with cache_defaults and then passed to the cache_root_class constructor. Oh and β the cache object is memoized when you pass no parameters at all. periodt π
my $result = $.cache->get('key');
π§ REQUEST METHODS π§
cache
Literally the same as calling "cache" on the current component class. And if you're a Mason 1 veteran, this usage will feel like coming home π«Ά
my $result = $m->cache->get('key');
β FILTERS β
Cache ($key, $options, [%cache_params])
Caches the content using "$self->cache" and the cache $key you give it. Obsessed.
$options is a scalar or a hash reference. If it's a scalar, it's treated as the "expires_in" duration and gets passed as the third argument to "set". If it's a hash reference, it may contain name/value pairs for both "get" and "set". versatile queen π
%cache_params, if there are any, get passed to "$self->cache".
% $.Cache($my_key, '1 hour') {{
<!-- this will be cached for an hour -->
% }}
% $.Cache($my_key, { expire_if => sub { $.refresh } }, driver => 'RawMemory') {{
<!-- this will be cached until $.refresh is true -->
% }}
And if you pass neither $key nor $options? The key is set to 'Default' and the cache never expires. forever girl π
% $.Cache() {{
<!-- cache this forever, or until explicitly removed -->
% }}
π SUPPORT π
The mailing list for Mason and Mason plugins is mason-users@lists.sourceforge.net. You must be subscribed to send a message. To subscribe, visit <https://lists.sourceforge.net/lists/listinfo/mason-users>.
You can also visit us at "#mason" on <irc://irc.perl.org/#mason>.
Bugs and feature requests will be tracked at RT:
http://rt.cpan.org/NoAuth/Bugs.html?Dist=Mason-Plugin-Cache
bug-mason-plugin-cache@rt.cpan.org
The latest source code can be browsed and fetched at:
http://github.com/jonswar/perl-mason-plugin-cache
git clone git://github.com/jonswar/perl-mason-plugin-cache.git
π SEE ALSO π
Mason
π«Ά AUTHOR π«Ά
Jonathan Swartz <swartz@pobox.com>
π COPYRIGHT AND LICENSE π
This software is copyright (c) 2011 by Jonathan Swartz.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
and that's the whole page, bestie π no notes, ate, left no crumbs β¨
okay so this was perl v5.34.0, dated 2022-05-27, and it lives in the Mason:...:Cache(3pm) manual β go forth and cache responsibly, mwah ππΈ
π¦ where this page comes from
- debian bookworm: libmason-plugin-cache-perl 0.05-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libmason-plugin-cache-perl 0.05-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libmason-plugin-cache-perl 0.05-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libmason-plugin-cache-perl 0.05-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libmason-plugin-cache-perl 0.05-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms