CodeRepository — specify directory containing code that can be included in the running installation when needed
There is a huge base of Interchange code (collection of UserTag
s and
CodeDef
s) included in the default installation.
Much of it is not needed for the usual installations,
causing a larger process memory profile than necessary.
Furthermore, it is hard to manually determine what subset of code is required,
especially when an ITL tag calls
$Tag->
which calls some filter which calls some sort of an action —
you get the idea.
TAGNAME
()
CodeRepository
allows building catalogs with a more optimal
set of code than just "everything".
CodeRepository
depends on a related directive, AccumulateCode
.
If AccumulateCode
is disabled, operation is traditional and everything
gets loaded at Interchange startup time. (There have
been some code initialization changes and routine calling changes,
but the data structures are identical and no difference in operation
should be seen).
It's when you remove the
ICROOT/code/
directory and
enable AccumulateCode
that things get interesting.
Interchange starts looking into CodeRepository
for pieces it finds
missing (ITL tags, ActionMaps, filters, widgets, etc.)
and compiles these as needed, in runtime!
The code is sent to the master process for compilation and
incorporation, so that on the next page access (or in the worst case,
after HouseKeeping
seconds), Interchange will find the code already compiled
and ready to go.
Fetched code blocks are copied to
.
When you restart Interchange the next time, these code blocks will be found,
read normally and need not be recompiled and loaded on the fly again.
$Global::TagDir
/Accumulated/
Over time, as you access pages and routines, a full set of tags
will be developed and you can then disable AccumulateCode
.
(In fact, AccumulateCode
is recommended only for development and should
really be turned off in production systems).
Example: Setting up CodeRepository
Put the following in interchange.cfg
:
AccumulateCode Yes CodeRepository /usr/interchange/code.pool/
To prepare the code.pool/
directory, you can do something like this:
$ mkdir /usr/interchange/code.pool/ $ mv /usr/interchange/code/* /usr/interchange/code.pool/
There can be failures due to calling $Tag->
from within
embedded
Perl for the first time, particularly when it uses a "MapRoutine" or
calls another TAGNAME
()$Tag->
within. This is due to
TAGNAME
()Safe
, and there is probably
not much to be done about it. The good news is that the error should
go away after HouseKeeping
seconds, when the tag gets compiled by the
master.
[area]
, [tmp]
, [tmpn]
, and [image]
are examples of tags known
to fail in this manner.
Tags that are frequently called
in this fashion should probably be manually placed in directory
code/Vital/
and not
be accumulated "by chance".
Anyway, this temporary failure could be avoided by listing catalog in the
AllowGlobal
directive, and it
might also be possible to make a directive that allows AllowGlobal
for
a catalog automatically, when in AccumulateCode
mode.
(If you don't want to trade immediate code loading for the lack of
AllowGlobal
protection, then just set HouseKeeping
to
something like 20 seconds
— and
only do it on your development system!)
One convenient side-effect is that you can easily load new code (such as new
Interchange tags) "on the fly" by simply adding files to the CodeRepository
directory. This alleviates the need for Interchange server restart.
It might also be possible to dynamically remove and
load code from the server in this manner, but this has yet
to be looked at.
![]() |
Warning |
---|---|
Nice features are often dangerous! Don't run this in production — you have been warned!
"OrderCheck"
Not fully tested in
Defining multiple tags or code blocks ( This feature only applies to global code — catalog-based code is not affected and behaves as usual. |
Interchange 5.9.0:
Source: lib/Vend/Config.pm
Line 3925 (context shows lines 3925-3932)
sub parse_root_dir { my($var, $value) = @_; return '' unless $value; $value = "$Global::VendRoot/$value" unless file_name_is_absolute($value); $value =~ s./+$..; return $value; }