albert has asked for the wisdom of the Perl Monks concerning the following question:
I'd be interested in limiting the number of cached statement handlers, as the caching is only really worthwhile when I am not constantly making new ones. Does anyone have a suggestion on how I could go about this?if (my $sth = $self->{$dbh}{$query}) { + warn "Using cached statement handler\n" if $self->debug; + return $sth; + } else { + warn "Creating new statement handler\n" if $self->debug; + $sth = $dbh->prepare($query) || $self->throw("Couldn't prepare que +ry $query:\n ".DBI->errstr."\n"); return $self->{$dbh}{$query} = $sth; + }
I was considering some sort of size limited tied hash, and then shifting an element off, but was looking at what others might suggest.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: how to limit size of hash
by Limbic~Region (Chancellor) on Oct 26, 2004 at 16:10 UTC | |
|
Re: how to limit size of hash
by gaal (Parson) on Oct 26, 2004 at 14:58 UTC | |
|
Re: how to limit size of hash
by revdiablo (Prior) on Oct 26, 2004 at 18:50 UTC | |
|
Re: how to limit size of hash
by hardburn (Abbot) on Oct 26, 2004 at 15:37 UTC | |
by albert (Monk) on Oct 26, 2004 at 15:44 UTC | |
|
Re: how to limit size of hash
by davido (Cardinal) on Oct 26, 2004 at 15:19 UTC |