Changeset 22433 for lang/perl/Method-Cached
- Timestamp:
- 10/31/08 16:16:22 (5 years ago)
- Location:
- lang/perl/Method-Cached/trunk
- Files:
-
- 2 modified
-
lib/Method/Cached.pm (modified) (2 diffs)
-
t/02-management.t (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lang/perl/Method-Cached/trunk/lib/Method/Cached.pm
r22060 r22433 136 136 use Method::Cached; 137 137 138 sub message :Cached(5) { 139 join ':', @_, time, rand 140 } 138 sub message :Cached(5) { join ':', @_, time, rand } 141 139 142 140 package main; … … 152 150 153 151 Method::Cached offers the following mechanisms: 152 154 153 The return value of the method is stored in storage, and 155 the value stored when being execute it next time is returned. 154 the value stored when being execute it next time is returned. 155 156 =head2 SETTING OF CACHED DOMAIN 157 158 In beginning logic or the start-up script: 159 160 use Method::Cached; 161 162 Method::Cached->default_domain({ 163 storage_class => 'Cache::FastMmap', 164 }); 165 166 Method::Cached->set_domain( 167 'some-namespace' => { 168 storage_class => 'Cache::Memcached::Fast', 169 storage_args => [ 170 { 171 # Parameter of constructor of class that uses it for cashe 172 servers => [ '192.168.254.2:11211', '192.168.254.3:11211' ], 173 ... 174 }, 175 ], 176 }, 177 ); 178 179 =head2 DEFINITION OF METHODS 180 181 This function is mounting used as an attribute of the method. 182 183 =over 4 184 185 =item B<:Cached ( DOMAIN_NAME, EXPIRES, [, KEY_RULE, ...] )> 186 187 The cached rule is defined specifying the domain name. 188 189 sub message :Cached('some-namespace', 60 * 5, LIST) { ... } 190 191 =item B<:Cached ( EXPIRES, [, KEY_RULE, ...] )> 192 193 When the domain name is omitted, the domain of default is used. 194 195 sub message :Cached(60 * 30, LIST) { ... } 196 197 =back 198 199 =head2 RULE TO GENERATE KEY 200 201 =over 4 202 203 =item B<LIST> 204 205 =item B<SERIALIZE> 206 207 =item B<SELF_SHIFT> 208 209 =item B<SELF_CODED> 210 211 =item B<PER_OBJECT> 212 213 =back 214 215 =head1 METHODS 216 217 =over 4 218 219 =item B<default_domain ($setting)> 220 221 =item B<set_domain (%domain_settings)> 222 223 =item B<get_domain ($domain_name)> 224 225 =back 156 226 157 227 =head1 AUTHOR -
lang/perl/Method-Cached/trunk/t/02-management.t
r22060 r22433 2 2 3 3 use strict; 4 use Test::More tests => 8;4 use Test::More tests => 7; 5 5 6 6 { … … 17 17 18 18 { 19 Method::Cached->import(20 -default => { storage_class => 'Cache::Memcached::Fast' },21 );22 is_deeply(23 Method::Cached->default_domain,24 {25 storage_class => 'Cache::Memcached::Fast',26 storage_args => [],27 key_rule => 'LIST',28 }29 );30 }31 32 {33 19 my $apps_1 = { 34 storage_class => 'Cache::Memcached::Fast', 35 storage_args => [ { servers => [qw/ 127.0.0.1:11211 /] }, ], 20 storage_class => 'Cache::FastMmap', 21 storage_args => [ 22 share_file => '/tmp/apps1_cache.bin', 23 unlink_on_exit => 1, 24 ], 25 key_rule => 'SERIALIZE', 36 26 }; 37 27 my $apps_2 = { … … 39 29 storage_args => [ 40 30 share_file => '/tmp/apps2_cache.bin', 41 unlink_on_exit => 0,31 unlink_on_exit => 1, 42 32 ], 33 key_rule => [qw/PER_OBJECT SERIALIZE/], 43 34 }; 44 35 Method::Cached->import(-domains => { … … 69 60 like $@, qr/^Can't load module:/; 70 61 } 62 63
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)