On Aug 23, 2013, at 12:22 PM, Vincent Veyron <[email protected]> wrote:
> As you can see, no caching happens when any callback is present in the
> connect method (connected, connect_cached.new, or
> connect_cached.reused).
Oh, you know what? I think this is why the example in the docs and my blog post
puts the callback into a lexical variable, then just passes that lexical. This
is because the params passed to connect_cached(), if they vary at all, create
different connections. You call connect_cached() three times, and construct the
Callbacks hash reference anew each time. So it is different each time.
Try this:
my $cb = {
'connect_cached.reused' => sub { print "reused!!!"; return; },
};
for my $test (1..3) {
my $cached_dbh = MyApp::SQLite->connect_cached(
"dbi:SQLite:dbname=$dbfile", '', '',
{
RaiseError => 1,
PrintError => 0,
Callbacks => $cb,
}
);
...
}
Best,
David