Skip to content

Commit

Permalink
Indices: make AS_RESULTS_FROM_LOCAL a proper param, not a cache entry
Browse files Browse the repository at this point in the history
Caches can be deleted with impunity so might be
interfered with in the middle of processing.
  • Loading branch information
shawnlaffan committed Feb 25, 2024
1 parent 466eeaa commit b7456f0
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions lib/Biodiverse/Indices.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 );
Expand Down
8 changes: 4 additions & 4 deletions lib/Biodiverse/Indices/Endemism.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions lib/Biodiverse/Indices/Indices.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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/);
Expand Down Expand Up @@ -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};

Expand Down

0 comments on commit b7456f0

Please sign in to comment.