Libravatar: Refactor cache handling to avoid unncessary stat
The basic pattern of the code we are dealing with is:
my $path = cache_location(...);
if (valid_cache($path)) {
...;
}
With cache_location possibly doing a stat() of $path and valid_cache
doing at least one stat() as well. Rewrite it so that cache_location
always stats and checks the cache (since we always need it). This way
we can now guarantee this flow requires at *most* 3 stats rather than
5.
The replacement for the above code becomes:
my ($path, $is_valid) = cache_location(...);
if ($is_valid) {
...;
}