Debian Codegraph @

README

raw
1 NAME
2 Mason::Plugin::Cache - Provide component cache object and filter
3
4 VERSION
5 version 0.05
6
7 SYNOPSIS
8 my $result = $.cache->get('key');
9 if (!defined($result)) {
10 ... compute $result ...
11 $.cache->set('key', $result, '5 minutes');
12 }
13
14 ...
15
16 % $.Cache('key2', '1 hour') {{
17 <!-- this will be cached for an hour -->
18 % }}
19
20 DESCRIPTION
21 Adds a `cache' method and `Cache' filter to access a cache (CHI) object
22 with a namespace unique to the component.
23
24 INTERP PARAMETERS
25 cache_defaults
26 Hash of parameters passed to cache constructor. Defaults to
27
28 driver=>'File', root_dir => 'DATA_DIR/cache'
29
30 which will create a basic file cache under Mason's data directory.
31
32 cache_root_class
33 Class used to create a cache. Defaults to CHI.
34
35 COMPONENT CLASS METHODS
36 cache
37 Returns a new cache object with the namespace set to the component's
38 path. Parameters to this method, if any, are combined with
39 cache_defaults and passed to the cache_root_class constructor. The
40 cache object is memoized when no parameters are passed.
41
42 my $result = $.cache->get('key');
43
44 REQUEST METHODS
45 cache
46 Same as calling `cache' on the current component class. This usage
47 will be familiar to Mason 1 users.
48
49 my $result = $m->cache->get('key');
50
51 FILTERS
52 Cache ($key, $options, [%cache_params])
53 Caches the content using `$self->cache' and the supplied cache
54 *$key*.
55
56 *$options* is a scalar or hash reference. If a scalar, it is treated
57 as the `expires_in' duration and passed as the third argument to
58 `set'. If it is a hash reference, it may contain name/value pairs
59 for both `get' and `set'.
60
61 *%cache_params*, if any, are passed to `$self->cache'.
62
63 % $.Cache($my_key, '1 hour') {{
64 <!-- this will be cached for an hour -->
65 % }}
66
67 % $.Cache($my_key, { expire_if => sub { $.refresh } }, driver => 'RawMemory') {{
68 <!-- this will be cached until $.refresh is true -->
69 % }}
70
71 If neither *$key* nor *$options* are passed, the key is set to
72 'Default' and the cache never expires.
73
74 % $.Cache() {{
75 <!-- cache this forever, or until explicitly removed -->
76 % }}
77
78 SUPPORT
79 The mailing list for Mason and Mason plugins is
80 [email protected]. You must be subscribed to send a
81 message. To subscribe, visit
82 https://lists.sourceforge.net/lists/listinfo/mason-users.
83
84 You can also visit us at `#mason' on irc:.
85
86 Bugs and feature requests will be tracked at RT:
87
88 http://rt.cpan.org/NoAuth/Bugs.html?Dist=Mason-Plugin-Cache
89 [email protected]
90
91 The latest source code can be browsed and fetched at:
92
93 http://github.com/jonswar/perl-mason-plugin-cache
94 git clone git://github.com/jonswar/perl-mason-plugin-cache.git
95
96 SEE ALSO
97 Mason
98
99 AUTHOR
100 Jonathan Swartz <[email protected]>
101
102 COPYRIGHT AND LICENSE
103 This software is copyright (c) 2011 by Jonathan Swartz.
104
105 This is free software; you can redistribute it and/or modify it under
106 the same terms as the Perl 5 programming language system itself.
107