From b7456f006e87cea05e368016d3cd3f2025153ff8 Mon Sep 17 00:00:00 2001 From: shawnlaffan Date: Sun, 25 Feb 2024 16:36:44 +1100 Subject: [PATCH] Indices: make AS_RESULTS_FROM_LOCAL a proper param, not a cache entry Caches can be deleted with impunity so might be interfered with in the middle of processing. --- lib/Biodiverse/Indices.pm | 4 ++-- lib/Biodiverse/Indices/Endemism.pm | 8 ++++---- lib/Biodiverse/Indices/Indices.pm | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/Biodiverse/Indices.pm b/lib/Biodiverse/Indices.pm index 6a69a0486..211f518ff 100644 --- a/lib/Biodiverse/Indices.pm +++ b/lib/Biodiverse/Indices.pm @@ -1552,7 +1552,7 @@ sub run_dependencies { my %results; my %as_results_from; # make sure this is new each iteration - $self->set_cached_value ($cache_name_local_results => \%as_results_from); + $self->set_param ($cache_name_local_results => \%as_results_from); foreach my $calc (@$calc_list) { my $calc_results; @@ -1591,7 +1591,7 @@ sub run_dependencies { } # We refresh each call above, but this ensures last one is cleaned up. - $self->delete_cached_value($cache_name_local_results); + $self->delete_param ($cache_name_local_results); if ( $type eq 'pre_calc_global' ) { $self->set_param( AS_RESULTS_FROM_GLOBAL => \%as_results_from_global ); diff --git a/lib/Biodiverse/Indices/Endemism.pm b/lib/Biodiverse/Indices/Endemism.pm index 03cd22ce4..32c062719 100644 --- a/lib/Biodiverse/Indices/Endemism.pm +++ b/lib/Biodiverse/Indices/Endemism.pm @@ -303,7 +303,7 @@ sub calc_endemism_central_hier_part { # If we have no nbrs in set 2 then we are the same as the "whole" variant. # So just grab its values if it has already been calculated. if (!keys %{$args{label_hash2}}) { - my $cache_hash = $self->get_cached_value('AS_RESULTS_FROM_LOCAL'); + my $cache_hash = $self->get_param('AS_RESULTS_FROM_LOCAL'); my $cached = $cache_hash->{calc_endemism_whole_hier_part}; if ($cached) { my %remapped; @@ -335,7 +335,7 @@ sub calc_endemism_whole_hier_part { # If we have no nbrs in set 2 then we are the same as the "central" variant. # So just grab its values if it has already been calculated. if (!keys %{$args{label_hash2}}) { - my $cache_hash = $self->get_cached_value('AS_RESULTS_FROM_LOCAL'); + my $cache_hash = $self->get_param('AS_RESULTS_FROM_LOCAL'); my $cached = $cache_hash->{calc_endemism_central_hier_part}; if ($cached) { # say STDERR join ' ', sort keys %$cached; @@ -586,7 +586,7 @@ sub _calc_endemism_central { # If we have no nbrs in set 2 then we are the same as the "whole" variant. # So just grab its values if it has already been calculated. if (!keys %{$args{label_hash2}}) { - my $cache_hash = $self->get_cached_value('AS_RESULTS_FROM_LOCAL'); + my $cache_hash = $self->get_param('AS_RESULTS_FROM_LOCAL'); my $cached = $cache_hash->{_calc_endemism_whole}; return wantarray ? %$cached : $cached if $cached; @@ -736,7 +736,7 @@ sub _calc_endemism_whole { # If we have no nbrs in set 2 then we are the same as the "central" variant. # So just grab its values if it has already been calculated. if (!keys %{$args{label_hash2}}) { - my $cache_hash = $self->get_cached_value('AS_RESULTS_FROM_LOCAL'); + my $cache_hash = $self->get_param('AS_RESULTS_FROM_LOCAL'); my $cached = $cache_hash->{_calc_endemism_central}; return wantarray ? %$cached : $cached if $cached; diff --git a/lib/Biodiverse/Indices/Indices.pm b/lib/Biodiverse/Indices/Indices.pm index 16c581b8a..ffe142d52 100644 --- a/lib/Biodiverse/Indices/Indices.pm +++ b/lib/Biodiverse/Indices/Indices.pm @@ -1702,7 +1702,7 @@ sub get_metadata__calc_abc_any { sub _calc_abc_any { my $self = shift; - my $cache_hash = $self->get_cached_value('AS_RESULTS_FROM_LOCAL'); + my $cache_hash = $self->get_param('AS_RESULTS_FROM_LOCAL'); my $cache_key = List::Util::first {defined $cache_hash->{$_}} (qw/calc_abc calc_abc2 calc_abc3/); @@ -1738,7 +1738,7 @@ sub get_metadata_calc_abc { sub calc_abc { # wrapper for _calc_abc - use the other wrappers for actual GUI stuff my ($self, %args) = @_; - my $cache_hash = $self->get_cached_value('AS_RESULTS_FROM_LOCAL'); + my $cache_hash = $self->get_param('AS_RESULTS_FROM_LOCAL'); my $cached = $cache_hash->{calc_abc2} || $cache_hash->{calc_abc3};