Don't use config cache for hook_config plugins

Conflig plugins can do their own caching:  there's no telling what might change
their return values over the life of the config cache.
This commit is contained in:
Jared Johnson 2014-09-12 05:13:49 -05:00
parent 50cc469881
commit 5b8138971a

View File

@ -145,46 +145,24 @@ sub config {
$self->log(LOGDEBUG, "in config($c)"); $self->log(LOGDEBUG, "in config($c)");
# first try the cache
# XXX - is this always the right thing to do? what if a config hook
# can return different values on subsequent calls?
my $is_address = (ref $type and $type->can('address')); my $is_address = (ref $type and $type->can('address'));
if ($_config_cache->{$c} and ! $is_address) {
$self->log(LOGDEBUG,
"config($c) returning (@{$_config_cache->{$c}}) from cache");
return wantarray ? @{$_config_cache->{$c}} : $_config_cache->{$c}->[0];
}
# then run the hooks
my @args = $is_address ? ('user_config',$type,$c) : ('config',$c); my @args = $is_address ? ('user_config',$type,$c) : ('config',$c);
my ($rc, @config) = $self->run_hooks_no_respond(@args); my ($rc, @config) = $self->run_hooks_no_respond(@args);
return wantarray ? @config : $config[0] if $is_address; return wantarray ? @config : $config[0] if $is_address;
$self->log(LOGDEBUG, "config($c): hook returned ($rc, @config) "); $self->log(LOGDEBUG, "config($c): hook returned ($rc, @config) ");
if ($rc == OK) { if ($rc == OK) {
$self->log(LOGDEBUG, return wantarray ? @config : $config[0];
"setting _config_cache for $c to [@config] from hooks and returning it"
);
$_config_cache->{$c} = \@config;
return wantarray ? @{$_config_cache->{$c}} : $_config_cache->{$c}->[0];
} }
# and then get_qmail_config # and then get_qmail_config
@config = $self->get_qmail_config($c, $type); @config = $self->get_qmail_config($c, $type);
if (@config) { if (@config) {
$self->log(LOGDEBUG, return wantarray ? @config : $config[0];
"setting _config_cache for $c to [@config] from get_qmail_config and returning it"
);
$_config_cache->{$c} = \@config;
return wantarray ? @{$_config_cache->{$c}} : $_config_cache->{$c}->[0];
} }
# finally we use the default if there is any: # finally we use the default if there is any:
if (exists($defaults{$c})) { if (exists($defaults{$c})) {
$self->log(LOGDEBUG, return wantarray ? @config : $config[0];
"setting _config_cache for $c to @{[$defaults{$c}]} from defaults and returning it"
);
$_config_cache->{$c} = [$defaults{$c}];
return wantarray ? @{$_config_cache->{$c}} : $_config_cache->{$c}->[0];
} }
return; return;
} }