[Catalyst-commits] r13740 - trunk/examples/CatalystAdvent/root/2010
dhoss at dev.catalyst.perl.org
dhoss at dev.catalyst.perl.org
Fri Dec 3 04:57:15 GMT 2010
Author: dhoss
Date: 2010-12-03 04:57:15 +0000 (Fri, 03 Dec 2010)
New Revision: 13740
Added:
trunk/examples/CatalystAdvent/root/2010/3.pod
Log:
publishing #3
Added: trunk/examples/CatalystAdvent/root/2010/3.pod
===================================================================
--- trunk/examples/CatalystAdvent/root/2010/3.pod (rev 0)
+++ trunk/examples/CatalystAdvent/root/2010/3.pod 2010-12-03 04:57:15 UTC (rev 13740)
@@ -0,0 +1,141 @@
+=pod
+
+This tutorial will show you how to:
+
+=over
+
+=item * Easily add resultset level caching to your
+Catalyst::Model::DBIC::Schema
+(http://search.cpan.org/perldoc?Catalyst%3A%3AModel%3A%3ADBIC%3A%3ASchema)
+calls.
+
+=item * Move your Catalyst::Plugin::Session
+(http://search.cpan.org/perldoc?Catalyst%3A%3APlugin%3A%3ASession) into
+memcached.
+
+=item * Have a convenient $ctx-E<gt>cache method available for anything
+else you might want to cache.
+
+=back
+
+B<Dependencies:>
+
+Memcached:
+
+=over
+
+=item * Cache::Memcached
+(http://search.cpan.org/perldoc?Cache%3A%3AMemcached)
+
+=item * Cache::Memcached::GetParserXS
+(http://search.cpan.org/perldoc?Cache%3A%3AMemcached%3A%3AGetParserXS)
+
+=back
+
+Catalyst Plugins:
+
+=over
+
+=item * Catalyst::Plugin::ConfigLoader
+(http://search.cpan.org/perldoc?Catalyst%3A%3APlugin%3A%3AConfigLoader)
+
+=item * Catalyst::Plugin::Session
+(http://search.cpan.org/perldoc?Catalyst%3A%3APlugin%3A%3ASession)
+
+=item * Catalyst::Plugin::Cache
+(http://search.cpan.org/perldoc?Catalyst%3A%3APlugin%3A%3ACache)
+
+=item * Catalyst::Plugin::Session::Store::Cache
+(http://search.cpan.org/perldoc?Catalyst%3A%3APlugin%3A%3ASession%3A%3AStore%3A%3ACache)
+
+=back
+
+DBIx::Class:
+
+=over
+
+=item * DBIx::Class::Cursor::Cached
+(http://search.cpan.org/perldoc?DBIx%3A%3AClass%3A%3ACursor%3A%3ACached)
+
+=back
+
+So dump all those in your Makefile.PL and you're halfway there.
+
+First we edit your Catalyst app's base package. Open up your version of
+MyApp.pm and add:
+
+ use Cache::Memcached::GetParserXS;
+ use Cache::Memcached;
+
+This will tell Cache::Memcached to use the XS Parser.
+
+Now, in the section where you load your plugins, add the new ones in:
+
+ use Catalyst qw/
+ ConfigLoader
+ Session
+ Cache
+ Session::Store::Cache
+ /;
+
+Now, configure Catalyst::Plugin::Cache. Here's an example for
+etc/myapp_local.pl:
+
+ #!/usr/bin/env perl
+ use strict;
+ use warnings;
+ return {
+ 'Plugin::Cache' => {
+ backend => {
+ namespace => 'myapp:',
+ class => 'Cache::Memcached',
+ servers => [ 'dev:11211' ]
+ }
+ }
+ };
+
+Note, I didn't use a .pl config just for kicks. Notice how the
+'servers' param takes an ArrayRef value. I tried and failed in
+expressing that in our Apache Conf style config, before realizing that
+ConfigLoader is just as happy to grab your .pl config alongside your
+regular config and merge them for you. Sometimes a cop-out is better
+than a hack.
+
+Now we configure our model. In our apache style conf it would look like
+this:
+
+ <Model::MyAppDB>
+ schema_class MyApp::Schema
+ <connect_info>
+ (your connect_info)
+ cursor_class DBIx::Class::Cursor::Cached
+ traits Caching
+ </connect_info>
+ </Model::MyAppDB>
+
+Pat yourself on the back, you should be done (unless something went
+horribly wrong).
+
+ my @sweet_loot = $ctx->model("MyAppDB::Loot")->search({ sweet => 1 },{ cache_for => 300 })->all;
+
+That $rs is now cached for 300 seconds. Look at
+DBIx::Class::Cursor::Cached
+(http://search.cpan.org/perldoc?DBIx%3A%3AClass%3A%3ACursor%3A%3ACached)
+for further explanation.
+
+ my $cache = $ctx->cache;
+ $cache->set('turtles',{ ilike => 'turtles' },600);
+ my $do_i_like_turtles = $cache->get('turtles');
+
+That's cached for 600 seconds. See Catalyst::Plugin::Cache
+(http://search.cpan.org/perldoc?Catalyst%3A%3APlugin%3A%3ACache) for
+the docs.
+
+=cut
+
+#Pod::HTML2Pod conversion notes:
+#From file memcached-dbix-class.html
+# 3884 bytes of input
+#Mon Nov 22 16:40:36 2010 skaufman
+# No a_name switch not specified, so will not try to render <a name='...'>
+# Will try to render <a href='...'>
More information about the Catalyst-commits
mailing list