On 10/11/06, Tim Bunce <[EMAIL PROTECTED]> wrote:
Whenever this topic has come up (which isn't very often) I've suggested
that people try tying the hash that CachedKids is a reference to.

Here's a slide from 2002 :-)

         http://search.cpan.org/src/TIMB/DBI_AdvancedTalk_2002/sld032.htm

Could you try out that approach? (I don't think anyone has yet.)

It has the added advantage of not adding any cost for people who don't
need it.

As it turns out, CPAN has Tie::Cache::LRU, which seems to already perfectly fit the bill, and is subclassable (for instance, Tie::Cache::LRU::Expires works great too, and also supports the "max_age" concept that was in my patch).  The job comes down to a one-liner this way.

How about a doc patch something like this, so people don't ask anymore?

-- Brandon
=== DBI.pm
==================================================================
--- DBI.pm	(revision 11195)
+++ DBI.pm	(local)
@@ -4257,7 +4257,13 @@
 which will ensure that prepare_cached only returns statements cached
 by that line of code in that source file. 
 
+If you'd like the cache to managed intelligently, you can tie the
+hashref returned by C<CachedKids> to an appropriate caching module,
+such as L<Tie::Cache::LRU>:
 
+  my $cache = $dbh->{CachedKids};
+  tie $cache, 'Tie::Cache::LRU', 500;
+
 =item C<commit>
 
   $rc  = $dbh->commit     or die $dbh->errstr;

Reply via email to