use strict;
use warnings;
+our $VERSION = "0.02";
+
use Scalar::Util ();
use Catalyst::Utils ();
use Carp ();
my %config = %$config;
if ( my $class = delete $config{class} ) {
- $app->setup_cache_backend_by_class( $name, $class, %config );
+ $app->setup_cache_backend_by_class( $name, $class, \%config );
} elsif ( my $store = delete $config->{store} || $app->default_cache_store ) {
my $method = lc("setup_${store}_cache_backend");
"Please consult the Catalyst::Plugin::Cache documentation on how to configure hetrogeneous stores."
unless $app->can($method);
- $app->$method( $name, %config );
+ $app->$method( $name, \%config );
} else {
$app->log->warn("Couldn't setup the cache backend named '$name'");
}
sub choose_cache_backend_wrapper {
my ( $c, @meta ) = @_;
- Carp::croak("meta data must be an even sized list") unless @meta % 2 == 0;
+ Carp::croak("metadata must be an even sized list") unless @meta % 2 == 0;
my %meta = @meta;
# ... params ...
};
- # ... in a controller
+ # In a controller:
sub foo : Local {
my ( $self, $c, $id ) = @_;
my $result;
unless ( $result = $cache->get( $id ) ) {
- # ... calulate result ...
+ # ... calculate result ...
$c->cache->set( $id, $result );
}
};
=head1 DESCRIPTION
-This plugin allows you to use a very simple configuration API without losing
-the possibility of flexibility when you need it later.
+This plugin gives you access to a variety of systems for caching
+data. It allows you to use a very simple configuration API, while
+maintaining the possibility of flexibility when you need it later.
-Amongst it's features are support for multiple backends, segmentation based on
-component or controller, keyspace partitioning and so forth, in various sub
-plugins.
+Among its features are support for multiple backends, segmentation based
+on component or controller, keyspace partitioning, and so more, in
+various subsidiary plugins.
=head1 METHODS
=item cache %meta
-Return a curried object with meta data from $profile_name or as explicitly
-specified.
+Return a curried object with metadata from C<$profile_name> or as
+explicitly specified.
-If a profile by the name $profile_name doesn't exist but a backend object by
-that name does exist, the backend will be returned instead, since the interface
-for curried caches and backends is almost identical.
+If a profile by the name C<$profile_name> doesn't exist, but a backend
+object by that name does exist, the backend will be returned instead,
+since the interface for curried caches and backends is almost identical.
-This method can also be called without arguments, in which case is treated as
-though the %meta hash was empty.
+This method can also be called without arguments, in which case is
+treated as though the C<%meta> hash was empty.
-See L</META DATA> for details.
+See L</METADATA> for details.
=item curry_cache %meta
-Return a L<Catalyst::Plugin::Cache::Curried> object, curried with %meta.
+Return a L<Catalyst::Plugin::Cache::Curried> object, curried with C<%meta>.
-See L</META DATA> for details.
+See L</METADATA> for details.
=item cache_set $key, $value, %meta
=item cache_remove $key, %meta
-These cache operations will call L<choose_cache_backend> with %meta, and then
-call C<set>, C<get> or C<remove> on the resulting backend object.
+These cache operations will call L<choose_cache_backend> with %meta, and
+then call C<set>, C<get>, or C<remove> on the resulting backend object.
=item choose_cache_backend %meta
-Select a backend object. This should return undef if no specific backend was
-selected - it's caller will handle getting C<default_cache_backend> on it's own.
+Select a backend object. This should return undef if no specific backend
+was selected - its caller will handle getting C<default_cache_backend>
+on its own.
This method is typically used by plugins.
=item temporary_cache_backend
-When no default cache backend is configured this method might return a backend
-known to work well with the current L<Catalyst::Engine>. This is a stup.
+When no default cache backend is configured this method might return a
+backend known to work well with the current L<Catalyst::Engine>. This is
+a stub.
=item
=back
-=head1 META DATA
+=head1 METADATA
=head2 Introduction
-Whenever you set or retrieve a key you may specify additional meta data that
-will be used to select a specific backend.
+Whenever you set or retrieve a key you may specify additional metadata
+that will be used to select a specific backend.
This metadata is very freeform, and the only key that has any meaning by
default is the C<backend> key which can be used to explicitly choose a backend
by name.
-The C<choose_cache_backend> method can be overridden in order to facilitate
-more intelligent backend selection. For example,
-L<Catalyst::Plugin::Cache::Choose::KeyRegexes> overrides that method to select
-a backend based on key regexes.
+The C<choose_cache_backend> method can be overridden in order to
+facilitate more intelligent backend selection. For example,
+L<Catalyst::Plugin::Cache::Choose::KeyRegexes> overrides that method to
+select a backend based on key regexes.
-Another example is a L<Catalyst::Plugin::Cache::ControllerNamespacing>, which
-that wraps backends in objects that perform key mangling, in order to keep
-caches namespaced per controller.
+Another example is a L<Catalyst::Plugin::Cache::ControllerNamespacing>,
+which wraps backends in objects that perform key mangling, in order to
+keep caches namespaced per controller.
However, this is generally left as a hook for larger, more complex
-applications. Most configurations should make due
+applications. Most configurations should make due XXXX
-The simplest way to dynamically select a backend is based on the L</Cache
-Profiles> configuratrion.
+The simplest way to dynamically select a backend is based on the
+L</Cache Profiles> configuration.
=head2 Meta Data Keys
=item key
-Supplied by C<cache_get>, C<cache_set> and C<cache_remove>.
+Supplied by C<cache_get>, C<cache_set>, and C<cache_remove>.
=item value
-Supplied by C<cache_set>
+Supplied by C<cache_set>.
=item caller
=item component
-The package name of the innermost caller who C<isa> L<Catalyst::Component>.
+The package name of the innermost caller who C<isa>
+L<Catalyst::Component>.
=item component_frame
=item controller
-The package name of the innermost caller who C<isa> L<Catalyst::Controller>.
+The package name of the innermost caller who C<isa>
+L<Catalyst::Controller>.
=item controller_frame
=back
-=head2 Meta Data Currying
+=head2 Metadata Currying
-In order to avoid specifying %meta over and over again you may call C<cache> or
-C<curry_cache> with %meta once, and get back a B<curried cache object>. This
-object responds to the methods C<get>, C<set> and C<remove>, by appending it's
-captured meta data and delegating them to C<cache_get>, C<cache_set> and
-C<cache_remove>.
+In order to avoid specifying C<%meta> over and over again you may call
+C<cache> or C<curry_cache> with C<%meta> once, and get back a B<curried
+cache object>. This object responds to the methods C<get>, C<set>, and
+C<remove>, by appending its captured metadata and delegating them to
+C<cache_get>, C<cache_set>, and C<cache_remove>.
This is simpler than it sounds.
...
};
-All configuration parameters should be provided in a hash reference under the
-C<cache> key in the C<config> hash.
+All configuration parameters should be provided in a hash reference
+under the C<cache> key in the C<config> hash.
=head2 Backend Configuration
Configuring backend objects is done by adding hash entries under the
-C<backends> keys in the main config.
+C<backends> key in the main config.
-A special case is that the hash key under the C<backend> (singular) key of the
-main config is assumed to be the backend named C<default>.
+A special case is that the hash key under the C<backend> (singular) key
+of the main config is assumed to be the backend named C<default>.
=over 4
};
$c->config->{cache}{backends}{large_things} = {
- class => "Cache::Memcached::Mangaed",
+ class => "Cache::Memcached::Managed",
data => '1.2.3.4:1234',
};
=item store
-Instrantiate a backend using a store plugin, e.g.
+Instantiate a backend using a store plugin, e.g.
$c->config->{cache}{backend} = {
store => "FastMmap",
};
-Store plugins typically require less configuration because they are specialized
-for L<Catalyst> applications. For example
+Store plugins typically require less configuration because they are
+specialized for L<Catalyst> applications. For example
L<Catalyst::Plugin::Cache::Store::FastMmap> will specify a default
-C<share_file>, and additionally use a subclass of L<Cache::FastMmap> that can
-also store non reference data.
+C<share_file>, and additionally use a subclass of L<Cache::FastMmap>
+that can also store non reference data.
The store plugin must be loaded.
=item profiles
-Supply your own predefined profiles for cache metadata, when using the C<cache>
-method.
+Supply your own predefined profiles for cache metadata, when using the
+C<cache> method.
For example when you specify
=back
-=head2 Misc Configuration
+=head2 Miscellaneous Configuration
=over 4
=item default_store
-When you do not specify a C<store> parameter in the backend configuration this
-one will be used instead. This configuration parameter is not necessary if only
-one store plugin is loaded.
+When you do not specify a C<store> parameter in the backend
+configuration this one will be used instead. This configuration
+parameter is not necessary if only one store plugin is loaded.
=back
=item store
-A plugin that provides backends of a certain type. This is a bit like a factory.
+A plugin that provides backends of a certain type. This is a bit like a
+factory.
=item cache
Stored key/value pairs of data for easy re-access.
-=item meta data
+=item metadata
-"extra" information about the item being stored, which can be used to locate an
-appropriate backend.
+"Extra" information about the item being stored, which can be used to
+locate an appropriate backend.
=item curried cache
my $cache = $c->cache(type => 'thumbnails');
$cache->set('pic01', $thumbnaildata);
-A cache which has been pre-configured with a particular set of namespacing
-data. In the example the cache returned could be one specifically tuned
-for storing thumbnails.
+A cache which has been pre-configured with a particular set of
+namespacing data. In the example the cache returned could be one
+specifically tuned for storing thumbnails.
-An object that responds to C<get>, C<set> and C<remove>, and will automatically
-add meta data to calls to C<< $c->cache_get >>, etc.
+An object that responds to C<get>, C<set>, and C<remove>, and will
+automatically add metadata to calls to C<< $c->cache_get >>, etc.
=back
=head1 SEE ALSO
-L<Cache> - the generic cache api on the CPAN.
+L<Cache> - the generic cache API on CPAN.
L<Catalyst::Plugin::Cache::Store> - how to write a store plugin.
regex matching on the keys. Can be used to partition the keyspace.
L<Catalyst::Plugin::Cache::ControllerNamespacing> - wrap backend objects in a
-name mangler so that every controller get's it's own keyspace.
+name mangler so that every controller gets its own keyspace.
-=cut
+=head1 AUTHOR
+
+Yuval Kogman, C<nothingmuch@woobling.org>
+
+=head1 COPYRIGHT & LICENSE
+Copyright (c) Yuval Kogman, 2006. All rights reserved.
+
+This library is free software, you can redistribute it and/or modify it under
+the same terms as Perl itself, as well as under the terms of the MIT license.
+
+=cut