in reply to my $cache = undef if undef;

What does this my $cache = undef if undef; do ?
Nothing! Remove the line.
Boris