Subsections


6. Cache


6.1 How does Cache work?

The template compilere generates an executable python file. This python file is placed into the template cache directory. Whenever the template this caching file was created from is used pyTemple tries to execute the python file generated earlier. By doing this resource intensive compiling is skipped.


6.2 Cache Modes

There are three different cache modes.

RECOMPILE_ALWAYS
Using this mode templates are only recompiled if there is no cached version of the file. This mode should be used in a production environment.
RECOMPILE_CHANGED
Using this mode templates are recompiled when the template file on the file system has been changed after the cached file has been created. You should use this mode if you are developing an application using pyTemple.
RECOMPILE_NEVER
Recompiles all template files everytime they are used. This should only be used when you are debugging pyTemple itself.

You may use these modes with the recompile parameter for the TplTemplate constructor.


6.3 Removing Cached Files

If you want to remove all cached files you can either directly remove all contents of the template cache directory or you can use TplEngine.delete_cached_files() and TplEngine.delete_cached_file(file_name). This is quite useful if you want to provide your customers an user interface to remove cached files so they can create their own template.

See About this document... for information on suggesting changes.