Mason:...:Cache(3pm)

πŸ“¦
version 0.05 Β· 2 versions
  • 0.05 Β· debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking (latest)
  • 0.05 Β· ubuntu jammy
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸŽ€ 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>


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