Re: DBIx::Class and caching

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: DBIx::Class and caching

Matt S Trout
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/

_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/dbix-class@...
Reply | Threaded
Open this post in threaded view
|

Re: DBIx::Class and caching

Matt S Trout
On Tue, Jun 24, 2008 at 02:13:15PM -0400, David Steinbrunner wrote:

> Andreas Pronakis wrote:
>
> > 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?
>
> Data::ObjectDriver has built in support for syncing row objects with all
> find, search, update and delete operations in a number of caching systems
> including Memcached.  I have a side project in progress to bring this same
> type of functionality DBIx:Class.  At this point it is quite rough but
> supports everything but search, at least in in the basically usage I have
> been testing it against so far.

Awesome.

Here's how we were thinking about making this easier:

Refactor DBIC to move every db call to go through the ResultSource object

Then your global/semiglobal find() etc. caches can live there (since this
is the only per-table per-connection object, you can't cache it in the
resultset because it's ephemeral and you can't cache it in the class
because then you're fucked with multiple databases).

Should be easy to just write a ResultSource mixin that then provides
whatever caching strategy you want.

Would you be interested in taking a branch off of 0.09/trunk and having a
go at this? I think if we got started with the refac the other people who've
been looking at the same stuff would probably turn up an help :)

--
      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/

_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/dbix-class@...