typo fixes and skeleton for first test
[gitmo/MooseX-Attribute-Cached.git] / lib / MooseX / Attribute / Cached.pm
CommitLineData
cf0ef7c5 1package MooseX::Attribute::Cached;
2
3use Moose;
4
5=head1 NAME
6
7MooseX::Attribute::Cached; Cache your Moose Attribute Value
8
9=head2 AUTHORITY
10
11cpan:JJNAPIORK
12
13=cut
14
15our $AUTHORITY = 'cpan:JJNAPIORK';
16
17=head1 VERSION
18
19Version 0.01
20
21=cut
22
23our $VERSION = '0.01';
24
25=head1 SYNOPSIS
26
27 package MyApp;
28
29 use Moose;
b5552897 30 use MooseX::Attribute::Cached;
cf0ef7c5 31
32 ## Cache Storage Options Declared Manually
33 has 'shared_key_1' => (
34 traits => ['Cached'],
35 cache_storage => ['Memcached' => {
36 'servers' => [ "10.0.0.15:11211", "10.0.0.15:11212"],
37 }],
38 %other_attribute_options_1,
39 );
40
41 ## This attribute get's it's cache storage from a method, which can be
42 ## called from a lazy attribute or as a package method
43 has 'shared_key_2' => (
44 traits => ['Cached'],
45 storage_key=>'something_different_shared_key_2',
46 %other_attribute_options_2,
47 );
48
49 ## Here's the provider for the attributes storage. Basically you need to
50 ## return the storage provider name and it's instantiation args.
51 sub _cache_storage_options_shared_key_2 {
52 ## If the calling attribute is lazy get's $self, otherwise we
53 ## gets __PACKAGE__. Getting $self could be useful if you are reading
54 ## the cache options from something like your config object, etc.
55 my $self = shift @_;
56 return [
57 'Memcached' => {
58 'servers' => [
59 "10.0.0.15:11211",
60 "10.0.0.15:11212",
61 "/var/sock/memcached",
62 "10.0.0.17:11211",
63 [ "10.0.0.17:11211", 3 ],
64 ],
65 'debug' => 0,
66 'compress_threshold' => 10_000,
67 },
68 ];
69 }
70
71 ## <Rest of your Class Definition>
72
73 1;
74
75=head1 DESCRIPTION
76
77Store the value of your Moose Attributes in a cached storage. The purpose of
78this is to faciliate sharing of attribute values over various processes or
79every across machines, presuming you are using a distributed cache,
80like Memcached. All instances with access to the same cache will share and
81update a common value. That way:
82
831) All instances share the same attribute slot. Updates made by one
84attribute are seen by all instances, even on different servers as long as
85they share a distributed caching system (such as Memcached).
86
872) It can be a sort of 'persistance lite' although I highly recommend using
88a real persistance system, such as a database or L<MooseX::Storage>.
89
903) You could probably use this as a sort of expensive class attribute, but
91you will likely be more happy with L<MooseX::ClassAttribute>
92
93At this time, this supports two Cachings systems, Memcached and FastMmap. If
94you have need for other cache types, adding a driver for it should be easy, so
95please send your patches and test cases.
96
97=head1 AUTHOR
98
99John Napiorkowski, C<< <john.napiorkowski at takkle.com> >>
100
101=head1 SUPPORT
102
103You can find documentation for this module with the perldoc command.
104
105 perldoc MooseX::Attributes::Cached
106
107You can also look for information at:
108
109=over 4
110
111=item * RT: CPAN's request tracker
112
113L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=MooseX-Attributes-Cached>
114
115=item * AnnoCPAN: Annotated CPAN documentation
116
117L<http://annocpan.org/dist/MooseX-Attributes-Cached>
118
119=item * CPAN Ratings
120
121L<http://cpanratings.perl.org/d/MooseX-Attributes-Cached>
122
123=item * Search CPAN
124
125L<http://search.cpan.org/dist/MooseX-Attributes-CachedF>
126
127=back
128
129=head1 SEE ALSO
130
131L<Moose>, L<MooseX::ClassAttribute>, L<MooseX::Storage>, L<Cache::FastMmap>,
132L<Cache::Memcached>
133
134=head1 COPYRIGHT & LICENSE
135
136Copyright 2008 John Napiorkowski, all rights reserved.
137
138This program is free software; you can redistribute it and/or modify it
139under the same terms as Perl itself.
140
141=cut
142
143no Moose; 1; # End of MooseX::Attributes::Cached