Skip Menu |

This queue is for tickets about the DBI CPAN distribution.

Report information
The Basics
Id: 31710
Status: resolved
Priority: 0/
Queue: DBI

People
Owner: Nobody in particular
Requestors: cpan [...] pjedwards.co.uk
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: 1.601
Fixed in: (no value)



Subject: prepare_cached - using a tied hash
Hello, (and thanks for DBI) I hope you can help me clarify some behaviour. In DBI.pm (version 1.601) in the section on prepare_cached, I'm wondering if: If you'd like the cache to managed intelligently, you can tie the hashref returned by CachedKids to an appropriate caching module, such as Tie::Cache::LRU: my $cache = $dbh->{CachedKids}; tie %$cache, 'Tie::Cache::LRU', 500; should be: If you'd like the cache to be managed intelligently, you can tie the hashref returned by CachedKids to an appropriate caching module, such as Tie::Cache::LRU: my $cache; tie %$cache, 'Tie::Cache::LRU', 500; $dbh->STORE('CachedKids',$cache); I can only get it to use the tied hash if I do the later. Here is my test code, I have a modified version of Tie::Cache::LRU that is printing to STDERR when Tie::Cache::LRU::Array FETCH is called. use strict; use warnings; use DBI; use Data::Dumper; use Tie::Cache::LRU; my $dsn = 'dbi:mysql:database=test;host=<hostname>;port=3306'; my $dbh = DBI->connect( $dsn, '<username>', '<password>' ); my $cache = $dbh->{CachedKids}; tie %$cache, 'Tie::Cache::LRU', 500; # I need to uncomment this to ensure CachedKids is TRUE # and prepare_cached does not set it to {} #$dbh->STORE('CachedKids', $cache); print "->{CachedKids} is "; if($dbh->{CachedKids}){ print "TRUE\n"; } else { print "FALSE\n"; } print Dumper($dbh->FETCH('CachedKids')); print "FETCH('CachedKids') is "; if($dbh->FETCH('CachedKids')){ print "TRUE\n"; } else { print "FALSE\n"; } my $sth = $dbh->prepare_cached( q{SELECT 'a'} ); $sth->execute(); my $rs = $sth->fetchall_arrayref( {} ); $sth->finish(); I'm not sure if it's the line: my $cache = $dbh->{CachedKids} ||= {}; in prepare_cached and/or the init value of $dbh->{CachedKids} and/or the way the tie is being done. I'm testing using version 0.21 of Tie::Cache::LRU from 2002 with Perl 5.8.7 on x86_64-linux. Thanks, Peter (Stig) Edwards
Subject: Re: [rt.cpan.org #31710] prepare_cached - using a tied hash
Date: Fri, 4 Jan 2008 17:15:58 +0000
To: Peter John Edwards via RT <bug-DBI [...] rt.cpan.org>
From: Tim Bunce <Tim.Bunce [...] pobox.com>
On Wed, Dec 19, 2007 at 11:39:14AM -0500, Peter John Edwards via RT wrote: Show quoted text
> > In DBI.pm (version 1.601) in the section on prepare_cached, I'm > wondering if: > > If you'd like the cache to managed intelligently, you can tie the > hashref returned by CachedKids to an appropriate caching module, such as > Tie::Cache::LRU: > > my $cache = $dbh->{CachedKids}; > tie %$cache, 'Tie::Cache::LRU', 500; > > should be: > > If you'd like the cache to be managed intelligently, you can tie the > hashref returned by CachedKids to an appropriate caching module, such as > Tie::Cache::LRU: > > my $cache; > tie %$cache, 'Tie::Cache::LRU', 500; > $dbh->STORE('CachedKids',$cache); > > I can only get it to use the tied hash if I do the later.
You're probably right. I'd never actually tested it :) Does it work when you change the last line to $dbh->{CachedKids} = $cache; I hope so as that would be neater. Please let me know. Tim.
From: cpan [...] pjedwards.co.uk
Show quoted text
> Does it work when you change the last line to > > $dbh->{CachedKids} = $cache;
Yes, this works, so the below would be good: If you'd like the cache to be managed intelligently, you can tie the hashref returned by CachedKids to an appropriate caching module, such as Tie::Cache::LRU: my $cache; tie %$cache, 'Tie::Cache::LRU', 500; $dbh->{CachedKids} = $cache; Thanks.
Docs updated for next release. Thanks.