Graham Barr wrote on 8/18/07 8:13 AM: > On Aug 17, 2007, at 3:53 PM, John Siracusa wrote: >>>> Finally, I suppose I could change the default implementation of >>>> init_db() to be more like this instead: >>>> >>>> sub init_db { $DB ||= Rose::DB->new } >>>> >>>> But that'd be quite a behavior change, and it'd have its own set >>>> of problems. >>> What are the problems here? Since I adopted this for the time >>> being it >>> would be nice to know what I have to expect... >> I just meant that it'd be a change in historic behavior that could >> break some people's code when they upgrade (not that RDBO is 1.0 yet, >> but it's still nice to avoid this kind of thing, if possible). > > Right. It would be a problem for people that use connections to > multiple databases from within the same application. > > If you are going to cache the Rose::DB object, you need to be smart > and make sure you are returning a Rose::DB object that was requested, > not just the previous on created. >
Awhile back I posted code that cached the DBI handle and re-used that, based on the domain/type/dsn of the Rose::DB object being requested. http://thread.gmane.org/gmane.comp.lang.perl.modules.dbi.rose-db-object/1794/focus=1802 What I hear you saying, Graham, is that it is a better idea to cache the Rose::DB object itself and not the DBI object it holds. Given that caching of database connections (either by caching Rose::DB objects or the DBI objects they hold) is an oft-repeated thread on this list, and given that John (quite rightly imo) doesn't want to put the caching behaviour into Rose::DB, I wonder if it would be worthwhile to have a Rose::DB::Persistent (Rose::DB::Cached?) subclass that does have smart object caching by default. Guess it would properly belong in the Rose::DBx namespace (or whatever that ended up being called). So I could get all the caching goodness just by doing: use base qw( Rose::DBx::Cached ); instead of: use base qw( Rose::DB ); and everything would Just Work the Same, except my db connections would be cached. I just know that I need connection caching, preferably at the Rose level, since I use Catalyst a lot and it is nice to move from the Cat dev server to Apache and back without needing to worry about Apache::DBI or some other server-dependent code. I'd be happy to take a first stab at such a module, if folks think it is a worthwhile idea. It sounds like enough folks have written their own caching logic into their RDBO projects that it's a wheel in want of invention, and it seems like having a 'standard' way to get the caching effect would be a worthwhile thing. Thoughts? -- Peter Karman . http://peknet.com/ . [EMAIL PROTECTED] ------------------------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/ _______________________________________________ Rose-db-object mailing list Rose-db-object@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rose-db-object