fixed issue #29: config now caches returned value
Qpsmtpd::config now checks cache, hooks, qmail_config, default in this order and returns the first match. In any case the returned value is stored in the cache, so subsequent calls to Qpsmtpd::config return the same value (unless the cache is cleared).
This commit is contained in:
parent
44c67fcbc7
commit
46171d0c66
@ -149,29 +149,41 @@ sub clear_config_cache {
|
||||
sub config {
|
||||
my ($self, $c, $type) = @_;
|
||||
|
||||
#my $timer = $SAMPLER->("config", undef, 1);
|
||||
$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?
|
||||
if ($_config_cache->{$c}) {
|
||||
$self->log(LOGDEBUG, "config($c) returning (@{$_config_cache->{$c}}) from cache");
|
||||
return wantarray ? @{$_config_cache->{$c}} : $_config_cache->{$c}->[0];
|
||||
}
|
||||
|
||||
$_config_cache->{$c} = [$defaults{$c}] if exists($defaults{$c});
|
||||
|
||||
#warn "SELF->config($c) ", ref $self;
|
||||
|
||||
# then run the hooks
|
||||
my ($rc, @config) = $self->run_hooks_no_respond("config", $c);
|
||||
@config = () unless $rc == OK;
|
||||
$self->log(LOGDEBUG, "config($c): hook returned ($rc, @config) ");
|
||||
if ($rc == OK) {
|
||||
$self->log(LOGDEBUG, "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];
|
||||
}
|
||||
|
||||
if (wantarray) {
|
||||
@config = $self->get_qmail_config($c, $type) unless @config;
|
||||
@config = $defaults{$c} if (!@config and $defaults{$c});
|
||||
return @config;
|
||||
# and then get_qmail_config
|
||||
@config = $self->get_qmail_config($c, $type);
|
||||
if (@config) {
|
||||
$self->log(LOGDEBUG, "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];
|
||||
}
|
||||
else {
|
||||
return $config[0] if defined($config[0]);
|
||||
my $val = $self->get_qmail_config($c, $type);
|
||||
return $val if defined($val);
|
||||
return $defaults{$c};
|
||||
|
||||
# finally we use the default if there is any:
|
||||
if (exists($defaults{$c})) {
|
||||
$self->log(LOGDEBUG, "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;
|
||||
|
||||
}
|
||||
|
||||
sub config_dir {
|
||||
|
Loading…
Reference in New Issue
Block a user