memoization for injected RPC functions is a very, very good thing
parent
27c1595cec
commit
5b78246d11
|
@ -107,6 +107,7 @@ sub rpc_call ($$;@) { #{{{
|
||||||
} #}}}
|
} #}}}
|
||||||
|
|
||||||
package IkiWiki::RPC::XML;
|
package IkiWiki::RPC::XML;
|
||||||
|
use Memoize;
|
||||||
|
|
||||||
sub getvar ($$$) { #{{{
|
sub getvar ($$$) { #{{{
|
||||||
my $plugin=shift;
|
my $plugin=shift;
|
||||||
|
@ -142,6 +143,7 @@ sub inject ($@) { #{{{
|
||||||
IkiWiki::Plugin::external::rpc_call($plugin, $params{call}, @_)
|
IkiWiki::Plugin::external::rpc_call($plugin, $params{call}, @_)
|
||||||
};
|
};
|
||||||
eval qq{*$params{name}=\$sub};
|
eval qq{*$params{name}=\$sub};
|
||||||
|
memoize($params{name}) if $params{memoize};
|
||||||
return 1;
|
return 1;
|
||||||
} #}}}
|
} #}}}
|
||||||
|
|
||||||
|
|
|
@ -78,6 +78,9 @@ example, make an RPC call to `inject`. Pass it named parameters "name" and
|
||||||
"Ikiwiki::rcs_update" and "call" is the RPC call ikiwiki will make whenever
|
"Ikiwiki::rcs_update" and "call" is the RPC call ikiwiki will make whenever
|
||||||
that function is run.
|
that function is run.
|
||||||
|
|
||||||
|
If the RPC call is memoizable, you can also pass a "memoize" parameter, set
|
||||||
|
to 1.
|
||||||
|
|
||||||
## Limitations of XML RPC
|
## Limitations of XML RPC
|
||||||
|
|
||||||
Since XML RPC can't pass around references to objects, it can't be used
|
Since XML RPC can't pass around references to objects, it can't be used
|
||||||
|
@ -112,7 +115,8 @@ number of calls.
|
||||||
Injecting a replacement for a commonly called ikiwiki function
|
Injecting a replacement for a commonly called ikiwiki function
|
||||||
could result in a lot more RPC calls than expected and slow
|
could result in a lot more RPC calls than expected and slow
|
||||||
eveything down. `pagetitle`, for instance, is called about 100 times
|
eveything down. `pagetitle`, for instance, is called about 100 times
|
||||||
per page build.
|
per page build. Memoizing injected functions whenever possible is a very
|
||||||
|
good idea.
|
||||||
|
|
||||||
In general, use common sense, and your external plugin will probably
|
In general, use common sense, and your external plugin will probably
|
||||||
perform ok.
|
perform ok.
|
||||||
|
|
|
@ -102,8 +102,9 @@ sub import {
|
||||||
|
|
||||||
# Here's an example of how to inject an arbitrary function into
|
# Here's an example of how to inject an arbitrary function into
|
||||||
# ikiwiki. Ikiwiki will be able to call bob() just like any other
|
# ikiwiki. Ikiwiki will be able to call bob() just like any other
|
||||||
# function.
|
# function. Note use of automatic memoization.
|
||||||
rpc_call("inject", name => "IkiWiki::bob", call => "bob");
|
rpc_call("inject", name => "IkiWiki::bob", call => "bob",
|
||||||
|
memoize => 1);
|
||||||
|
|
||||||
# Here's an exmaple of how to access values in %IkiWiki::config.
|
# Here's an exmaple of how to access values in %IkiWiki::config.
|
||||||
print STDERR "url is set to: ".
|
print STDERR "url is set to: ".
|
||||||
|
|
Loading…
Reference in New Issue