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 {
|
sub config {
|
||||||
my ($self, $c, $type) = @_;
|
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}) {
|
if ($_config_cache->{$c}) {
|
||||||
|
$self->log(LOGDEBUG, "config($c) returning (@{$_config_cache->{$c}}) from cache");
|
||||||
return wantarray ? @{$_config_cache->{$c}} : $_config_cache->{$c}->[0];
|
return wantarray ? @{$_config_cache->{$c}} : $_config_cache->{$c}->[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
$_config_cache->{$c} = [$defaults{$c}] if exists($defaults{$c});
|
# then run the hooks
|
||||||
|
|
||||||
#warn "SELF->config($c) ", ref $self;
|
|
||||||
|
|
||||||
my ($rc, @config) = $self->run_hooks_no_respond("config", $c);
|
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) {
|
# and then get_qmail_config
|
||||||
@config = $self->get_qmail_config($c, $type) unless @config;
|
@config = $self->get_qmail_config($c, $type);
|
||||||
@config = $defaults{$c} if (!@config and $defaults{$c});
|
if (@config) {
|
||||||
return @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]);
|
# finally we use the default if there is any:
|
||||||
my $val = $self->get_qmail_config($c, $type);
|
if (exists($defaults{$c})) {
|
||||||
return $val if defined($val);
|
$self->log(LOGDEBUG, "setting _config_cache for $c to @{[$defaults{$c}]} from defaults and returning it");
|
||||||
return $defaults{$c};
|
$_config_cache->{$c} = [$defaults{$c}];
|
||||||
|
return wantarray ? @{$_config_cache->{$c}} : $_config_cache->{$c}->[0];
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sub config_dir {
|
sub config_dir {
|
||||||
|
Loading…
Reference in New Issue
Block a user