sub EXISTS { my ($a,$key) = (shift, shift); # STEP 1 return 1 if exists $a->[0]{$key}; # Have data # STEP 2 my $cache = $a->[1]{$key}; return $cache if defined $cache; # Existence cache # STEP 3 my @res = $a->[3]($key,$a->[4]); $_[0][1]{$key} = 0, return unless @res; # Cache non-existence # STEP 4 # Now we know it exists return ($_[0][1]{$key} = 1) if $a->[5]; # Only existence reported # STEP 5 # Now know the value $_[0][0]{$key} = $res[0]; # Store data return 1 }