sub _build_cache_key {
my ($class, $storage, $args, $attrs) = @_;
- return Digest::SHA1::sha1_hex(Storable::nfreeze([ $args, $attrs ]));
+ # compose the query and bind values, like as_query(),
+ # so the cache key is only affected by what the database sees
+ # and not any other cruft in $attrs
+ my $ref = $storage->_select_args_to_query(@{$args}[0..2], $attrs);
+ my $connect_info = $storage->_dbi_connect_info;
+ my ($dbname, $username);
+ if (ref($connect_info->[0]) eq 'CODE') {
+ my $dbh = $connect_info->[0]->();
+ $dbname = $dbh->{Name};
+ $username = $dbh->{Username} || '';
+ } else {
+ $dbname = $connect_info->[0];
+ $username = $connect_info->[1] || '';
+ }
+
+ local $Storable::canonical = 1;
+ return Digest::SHA1::sha1_hex(Storable::nfreeze( [ $ref, $dbname, $username ] ));
+
}
sub _fill_data {