Caching XSLT

 

Caching XSLT

Caching XSLT

Enfold Proxy has a number of features to support XSLT transformation of the proxied content. If this feature is enabled, EP will examine the responses for XML content with style sheet information and transform the content before returning it to the client.

While this feature can reduce the load on the proxied servers, it increases the load on EP, and thus IIS, on the front-end machine. This document describes this feature, and the configuration options available to help reduce this load.

Note: All 64 bit versions of Enfold Proxy now support XSLT caching. (In EP version 6, only 32 bit versions supported XSLT caching).

Enabling XSLT

XSLT processing is enabled in each [host] section - see the XSLT options in the host configuration for more details.

XSLT Features

The Wikipedia Article on XSLT describes XSLT as 'designed to transform XML documents into other XML or "human-readable" documents'. Thus, if your remote server is producing XML content, Enfold Proxy can use XSLT to transform this data into human-readable HTML. An advantage of this technique is that it means the back-end is free to concentrate on the data and shift the load related to presenting this data (i.e., formatting it into HTML) into EP. Note that in some situations this may actually be a disadvantage - if your IIS site is already heavily loaded, it may not be an appropriate solution. This feature also adds to the memory load on IIS - each file referenced by a transform is loaded into memory before the processing can complete.

Enfold Proxy will follow all style sheet references contained in the XML. Alternatively, a header 'XSLTStylesheet' may be set, which will override any XSLT processing instructions in the XML.

XSLT Caching

Enfold Proxy supports two kinds of caching in XSLT processing.

  • A disk based cache which is very similar to the other caches implemented by EP. It stores copies of the XML and XSL files used by the transformation process, and supports all normal HTTP cache semantics (e.g., Last-Modified checking, Cache-Control headers and other features that allow custom settings for each item) and can be purged.

    This disk based cache does not lose any data when EP is restarted and stores the original content as supplied by the proxied server.

    All options prefixed with 'cache_' are referring to this cache.

  • An in-memory cache of style sheets. This cache stores a fully processed style sheet "tree" with all necessary files already fetched and parsed. It is not a copy of what was received from a remote server - it is an object in memory which represents the result of some XSLT processing. It cannot be purged, is unable to have items validated or have any setting overridden per style sheet. The contents are lost when EP is stopped.

    All options prefixed with 'object_cache_' are referring to this cache.

Important Note: XSLT caching is not currently supported on Windows Vista 64 bit.

Activate and Test XSLT Caching

Because XSLT caching is an in-memory cache (instead of disk-based cache), the method for verifying that it works is less direct. Unlike other cache hits, XSLT caching will not give a X-Cache: HIT message in the host headers, nor will it appear in the cache logs. You will however be able to see a brief message confirming an xslt cache hit in the proxy.log file. It looks like this:

2008-05-09 15:05:05,062|enfold.lxml|INFO|2076|3452|XSLT object cache hit for 'http://localhost/cdcatalog.xsl'
2008-05-09 15:05:05,108|enfold.lxml|INFO|2076|2460|XSLT object cache hit for 'http://localhost/cdcatalog.xsl'

For this example, you will add an XSL file into Zope (so it is stored as an object) and a python script which essentially outputs an XML file. This example will put cdcatalog.xml and cdcatalog.xsl into the application root level of the ZMI.

  1. Use the ZMI to add a python script which you will name cdcatalog.xml.

    • Follow the same steps that you did for adding a Plone site. From the Add dropdown menu in the ZMI, select Script (Python). (http://localhost:8080/manage).
    • For ID type cdcatalog.xml. Press Save and Edit.
    • Copy this XML python script (named cdcatalog.xml) into the edit box and press Save. This python script causes a simple XML file to be outputted by Zope. Note: This is not actually an xml file but a python script to output XML.
  2. Copy and paste the cdcatalog.xsl file. (You can download the same file here http://www.w3schools.com/xsl/cdcatalog.xsl). You might need to change the file extension so that it ends in ".xsl".

  1. Use the ZMI to add this xsl file in the same directory as your python script.

    • Select File from the Add dropdown menu.
    • Give it id cdcatalog.xsl and select Browse to find the file on your PC.
    • Be sure both objects are in the same directory and accessible. The easiest way is to try to access http://localhost/cdcatalog.xml and http://localhost/cdcatalog.xsl.
  2. Configure your Enfold Proxy settings by manually editing the eep.ini file in your C:\Program Files\Enfold Proxy directory. (Be sure to read the tips for manually editing the eep.ini file ). Important: You can enable XSLT caching only by manually editing the eep.ini file.

    Here is an example of how your eep.ini settings will appear when caching XSLT.

    [xslt]
    cache_default_age = 6000
    cache_enabled = True
    object_cache_enabled = True
    object_cache_max_len = 120
    
    
    [host originalfunsite]
    site = 998577302
    excludes = java_application
    auto_excludes = fsdirs
    xslt_enabled = True
    

The first section [xslt] contains global settings which will apply for any proxy definitions which have XSLT enabled. The second section [host originalfunsite] contains the settings for a proxy definition called originalfunsite. In this case, the proxy definition included an exclude and is associated with a IIS site having an ID of 998577302. To find out the ID for the IIS site associated with the proxy definition, run eepcheck.ini utility file. (See Using eepcheck.ini ).

In other words, you need to create a section called [xslt] and include parameters for object cache. For example object_cache_enabled must be set to true to cache XSLT files. You also must include xslt_enabled = True underneath the proxy definition (which in this case is originalfunsite).

The general settings in the XSLT can be modified according to your hardware requirements. When you cache XSLT you are actually caching objects (see the introduction); therefore, the main settings to affect performance of XSLT caching will be those which begin with object_cache_.
  1. Run the command line tool eep.exe file in your C:\Program Files\Enfold Proxy directory. This will make Internet Information Services (IIS) aware of the new changes you have made. (You may also need to restart IIS).
  2. Test the URLs in the browser. (If you tested it at application root, the URL will be http://localhost/cdcatalog.xml ). If XSLT caching works, you will see a formatted and stylized HTML file with a table, two columns and a green header. The page should say 'My CD Collection' in large letters. If you don't see one and see the raw XML file instead, then you need to recheck your settings. You should also consult the proxy.log file to check for error messages. (See Using Your Logs ).