git://git.camperquake.de
/
videosite.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
libvideosite: Add config caching
[videosite.git]
/
libvideosite.pm
diff --git
a/libvideosite.pm
b/libvideosite.pm
index
01fa7d9
..
3554201
100644
(file)
--- a/
libvideosite.pm
+++ b/
libvideosite.pm
@@
-34,6
+34,8
@@
my $getter;
my %builtin_config = ();
my $builtin_config_path;
my $builtin_config_default;
my %builtin_config = ();
my $builtin_config_path;
my $builtin_config_default;
+my $config_cache = 0;
+my %config_cache = ();
our $error;
#
our $error;
#
@@
-124,6
+126,10
@@
my $videosite_commands = {
'nodebug' => sub {
_cmd_nodebug(@_);
},
'nodebug' => sub {
_cmd_nodebug(@_);
},
+
+ 'cache' => sub {
+ _cmd_cache(@_);
+ },
};
#
};
#
@@
-153,7
+159,7
@@
sub _io {
#
@text = map { defined($_)?$remote_api->{quote}->($_):'(undef)' } @text;
#
@text = map { defined($_)?$remote_api->{quote}->($_):'(undef)' } @text;
- $outputstack[0]->{
ewpf
}->(sprintf($format, @text));
+ $outputstack[0]->{
io
}->(sprintf($format, @text));
}
#
}
#
@@
-301,36
+307,53
@@
sub _load_modules($) {
#
sub _config_get {
my $path = shift;
#
sub _config_get {
my $path = shift;
+ my $dotpath = join('.', @{$path});
my $value;
my $value;
- $value = $remote_api->{config_get}->($path);
- _debug("config: getting %s=%s", join('.', @{$path}), $value);
+ if ($config_cache && exists($config_cache{$dotpath}) && exists($config_cache{$dotpath}->{value})) {
+ $value = $config_cache{$dotpath}->{value};
+ } else {
+ $value = $remote_api->{config_get}->($path);
+ $config_cache{$dotpath} = {value => $value, has => 1};
+
+ }
+ _debug("config: getting %s=%s", $dotpath, $value);
return $value;
}
sub _config_set {
my $path = shift;
return $value;
}
sub _config_set {
my $path = shift;
+ my $dotpath = join('.', @{$path});
my $value = shift;
my $value = shift;
- _debug("config: setting %s=%s", join('.', @{$path}), $value);
+ _debug("config: setting %s=%s", $dotpath, $value);
+ $config_cache{$dotpath} = {value => $value, has => 1};
return $remote_api->{config_set}->($path, $value);
}
sub _config_has {
my $path = shift;
return $remote_api->{config_set}->($path, $value);
}
sub _config_has {
my $path = shift;
+ my $dotpath = join('.', @{$path});
my $b;
my $b;
- $b = $remote_api->{config_has}->($path);
- _debug("config: testing %s (%s)", join('.', @{$path}), $b?'true':'false');
+ if ($config_cache && exists($config_cache{$dotpath}) && exists($config_cache{$dotpath}->{has})) {
+ $b = $config_cache{$dotpath}->{has};
+ } else {
+ $b = $remote_api->{config_has}->($path);
+ $config_cache{$dotpath}->{has} = $b;
+ }
+ _debug("config: testing %s (%s)", $dotpath, $b?'true':'false');
return $b;
}
sub _config_del {
my $path = shift;
return $b;
}
sub _config_del {
my $path = shift;
+ my $dotpath = join('.', @{$path});
- _debug("config: removing %s", join('.', @{$path}));
+ _debug("config: removing %s", $dotpath);
+ delete($config_cache{$dotpath});
$remote_api->{config_del}->($path);
}
$remote_api->{config_del}->($path);
}
@@
-907,6
+930,18
@@
sub _cmd_nodebug {
}
}
}
}
+#
+# Display the content of the config cache
+#
+sub _cmd_cache {
+ my $event = shift;
+
+ _io("Content of config cache:");
+ foreach (sort(keys(%config_cache))) {
+ _io("%s => %s", $_, Dumper($config_cache{$_}));
+ }
+}
+
#
# Return the list of loaded grabbers.
#
# Return the list of loaded grabbers.
@@
-1086,7
+1121,11
@@
sub register_api {
$builtin_config_default = $a->{_config_default}->();
}
$builtin_config_default = $a->{_config_default}->();
}
- @outputstack = ({ewpf => $remote_api->{'io'}, window => ""});
+ if (exists($a->{_config_cache})) {
+ $config_cache = $a->{_config_cache}->();
+ }
+
+ @outputstack = ({io => $remote_api->{'io'}, window => ""});
return 1;
}
return 1;
}