[Dbix-class] DBIx::Class and caching

Matt S Trout dbix-class at trout.me.uk
Sun Jul 20 01:02:44 BST 2008


On Tue, Jun 24, 2008 at 07:43:12AM -0700, Andreas Pronakis wrote:
> Forgive me if this question sounds like asking for baby step instructions  but I hope it will benefit other DBIx::Class starters.
> 
> We have a lot of procedural code that we are looking to convert to DOM (Domain Object Modeling) and one of the tools we are lokoing to use is DBIx::Class (instead of writing our own Model which could be fun but a maintenance nightmare).
> 
> Anyway, the set up, we are look is mod_perl, DBIx::Class, MySQL backend, and some sort of MVC concept but we will not (for now) be using Catalyst (don't ask why).
> 
> Based on the above information my questions are:
> 1. ResultSet has a couple of methods related to caching, but going by the example given (http://search.cpan.org/~ash/DBIx-Class-0.08010/lib/DBIx/Class/ResultSet.pm#cache)  it seems like you have to turn caching on a per search()/find() call, is there some way of turning it on for the whole class (even better all classes) in one place (i.e. Parent class that all other classes inherit from)? 

You can set the default rs attributes on the ResultSource via

__PACKAGE__->resultset_attributes() in your row class file

and globally for the schema via

__PACKAGE__->default_resultset_attributes in your ::Schema subclass.

> 3. Can we cache SQL natively in DBIx::Class i.e. the SQL executed by a find, search or manual SELECT - I guess if 1 and 1.1 are supported SQL caching might be redundant except from manual SELECTs?

DBIx::Class automatically caches prepared statements and reuses them

> 4. If there isn't native support for the above, can someone give me any advice and/or examples regarding using DBIx::Class and MemCache to achieve the same result?
> 5. I came across the module DBIx::Class::Cursor::Cached but since the documentation is a bit on the thin side, I was wondering if someone can explain it in a bit more detail.  For example is it possible to use it to achieve points 1/1.1 and also set a default cache_for periodf for a whole class, rather than individual search requests? 

See my responses to (1), and I'd love a doc patch showing some examples.

-- 
      Matt S Trout       Need help with your Catalyst or DBIx::Class project?
   Technical Director                    http://www.shadowcat.co.uk/catalyst/
 Shadowcat Systems Ltd.  Want a managed development or deployment platform?
http://chainsawblues.vox.com/            http://www.shadowcat.co.uk/servers/



More information about the DBIx-Class mailing list