1Mojolicious::Plugin::CHUIs(e3r)Contributed Perl DocumentMaotjioolnicious::Plugin::CHI(3)
2
3
4
6 Mojolicious::Plugin::CHI - Use CHI Caches in Mojolicious
7
9 # Mojolicious
10 $app->plugin(CHI => {
11 MyCache => {
12 driver => 'FastMmap',
13 root_dir => '/cache',
14 cache_size => '20m'
15 }
16 });
17
18 # Mojolicious::Lite
19 plugin 'CHI' => {
20 default => {
21 driver => 'Memory',
22 global => 1
23 }
24 };
25
26 # In Controllers:
27 $c->chi('MyCache')->set(my_key => 'This is my value');
28 print $c->chi('MyCache')->get('my_key');
29
30 # Using the default cache
31 $c->chi->set(from_memory => 'With love!');
32 print $c->chi->get('from_memory');
33
35 Mojolicious::Plugin::CHI is a simple plugin to work with CHI caches
36 within Mojolicious.
37
39 register
40 # Mojolicious
41 $app->plugin(CHI => {
42 MyCache => {
43 driver => 'FastMmap',
44 root_dir => '/cache',
45 cache_size => '20m'
46 },
47 default => {
48 driver => 'Memory',
49 global => 1
50 },
51 namespaces => 1
52 });
53
54 # Mojolicious::Lite
55 plugin 'CHI' => {
56 default => { driver => 'Memory', global => 1 }
57 };
58
59 # Or in your config file
60 {
61 CHI => {
62 default => {
63 driver => 'Memory',
64 global => 1
65 }
66 }
67 }
68
69 Called when registering the plugin. On creation, the plugin accepts a
70 hash of cache names associated with CHI objects. All cache handles are
71 qualified CHI namespaces. You can omit this mapping by passing a
72 "namespaces" parameter with a "false" value. The handles have to be
73 unique, i.e. you can't have multiple different "default" caches in
74 mounted applications using Mojolicious::Plugin::Mount. Logging
75 defaults to the application log, but can be overridden using
76 on_get_error and on_set_error.
77
78 All parameters can be set as part of the configuration file with the
79 key "CHI" or on registration (that can be overwritten by
80 configuration).
81
82 Use custom CHI subclasses by passing a "chi_class" parameter with the
83 class name of a CHI subclass.
84
86 chi
87 # In Controllers:
88 $c->chi('MyCache')->set(my_key => 'This is my value', '10 min');
89 print $c->chi('MyCache')->get('my_key');
90 print $c->chi->get('from_default_cache');
91
92 Returns a CHI handle if registered. Accepts the name of the registered
93 cache. If no cache handle name is given, a cache handle name "default"
94 is assumed.
95
97 The following commands are available when the plugin is registered.
98
99 chi list
100 perl app.pl chi list
101
102 List all CHI caches associated with your application.
103
104 chi purge
105 perl app.pl chi purge mycache
106
107 Remove all expired entries from the cache namespace.
108
109 chi clear
110 perl app.pl chi clear mycache
111
112 Remove all entries from the cache namespace.
113
114 chi expire
115 perl app.pl chi expire mykey
116 perl app.pl chi expire mycache mykey
117
118 Set the expiration date of a key to the past. This does not
119 necessarily delete the data, but makes it unavailable using "get".
120
121 chi remove
122 perl app.pl chi remove mykey
123 perl app.pl chi remove mycache mykey
124
125 Remove a key from the cache.
126
128 Mojolicious, CHI.
129
130 Note: Old versions of CHI had a lot of dependencies. It was thus not
131 recommended to use this plugin in a CGI environment. Since new versions
132 of CHI use Moo instead of Moose, more use cases may be possible.
133
135 Boris Däppen <https://github.com/borisdaeppen>
136
137 Renée Bäcker <https://github.com/reneeb>
138
139 Rouzier <https://github.com/rouzier>
140
141 Mohammad S Anwar <https://github.com/manwar>
142
144 https://github.com/Akron/Mojolicious-Plugin-CHI
145
147 Copyright (C) 2012-2018, Nils Diewald <http://nils-diewald.de/>.
148
149 This program is free software, you can redistribute it and/or modify it
150 under the terms of the Artistic License version 2.0.
151
152
153
154perl v5.28.1 2018-11-14 Mojolicious::Plugin::CHI(3)