Skip to content

Commit

Permalink
Matrices: cache the summary stats
Browse files Browse the repository at this point in the history
Need to take care when updating that the cache is cleared,
but generally the summary stats are called after the matrix
has been finalised.
  • Loading branch information
shawnlaffan committed Sep 23, 2023
1 parent 407e5fa commit 41e4b4a
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/Biodiverse/Matrix.pm
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,12 @@ sub get_max_value {
sub get_summary_stats {
my $self = shift;

state $cachename = 'SUMMARY_STATS';
my $cached = $self->get_cached_value ($cachename);

return wantarray ? %$cached : $cached
if $cached;

my %data;
\my %top_level = $self->{BYELEMENT};
foreach my $href (values %top_level) {
Expand All @@ -415,6 +421,8 @@ sub get_summary_stats {
$r{$key} = $self->round_to_precision_aa($r{$key}, PRECISION) + 0;
}

$self->set_cached_value($cachename => \%r);

return wantarray ? %r : \%r;
}

Expand Down

0 comments on commit 41e4b4a

Please sign in to comment.