DBIx::Class cache quiz

Assume 'Artist' is a table with 10 rows

# http://search.cpan.org/perldoc?DBIx::Class::ResultSet#cache
my $rs = $schema->resultset('Artist')->search(
{ cache => 1 },
my @artists = $rs->all;
pop (@artists);

my $count1 = $rs->count;
my $count2 = scalar $rs->all;
my $count3 = scalar $rs->get_column('id')->all;

Q1: What are the values of $count1, $count2 and $count3?

A1: 9, 9, 10.

Q2: Why?

A2: $rs is a cached result set. Some methods on $rs return the cached results. Some don't and query the underlying db table(s).

Q3: Which ones do & which ones don't?

Leave a comment

About minty

user-pic I blog about Perl.