#### Contents

How does the caching work in Swiff Chart Generator?
When to use the caching?
The caching parameters
How to enable the caching on Windows?
How to enable the caching on UNIX?
The caching API
Examples
The Swiff Chart Generator Control Panel

#### How does the caching work in Swiff Chart Generator?

Swiff Chart Generator has a built-in caching support.

When caching is enabled, Swiff Chart Generator stores the data, the layout parameters as well as the corresponding generated chart data in a cache directory on the hard disk.

Each time a client requests the same chart (same data series, same chart style and parameters), the server simply sends back the previously generated Flash movie or image without having to re-generate it, thus considerably improving the performance. Once a chart is stored in the cache, the server does not consume CPU for movie or image regeneration.

The cache is automatically managed by Swiff Chart Generator so that it never allocates more than the maximum amount of disk memory specified by the configuration.

#### When to use the caching?

If tha data being graphed is often the same, using the cache is recommended. Enabling the cache is such cases will highly improve the performance. On the contrary, if the data being graphed is never, or rarely the same, using the cache is not recommended.

#### The Caching parameters

In Swiff Chart Generator, the caching has 3 different parameters:

- The Cache Name. The Cache Name specifies the location on the web server of the generated chart data which have been stored for caching. This location is called "the public cache" since it is accessible by web users. By default the cache name is "/charts_cache", relative to the web server root. Swiff Chart Generator always interprets the Cache Name as a location on the web server, never as a path on the file system.
- The Cache Size. The Cache Size specifies the maximum size of the cache in KB. By default the Cache Size is 4096KB (4 MB). Each time the cache reaches its maximum capacity, the last generated charts stored in the cache are removed.
- The Private Cache Directory (Optional). The Private Cache Directory is mainly a security option. By default the public cache records the index files necessary for charts caching. For security reasons, you may want to store these index files (which record private parameters) in a directory which is not accessible by web users. Contrary to the Cache Name, the Private Cache Directory specifies an absolute pathname on the file system. By default the Private Cache Directory is not used and private index files are stored in the public cache.

#### How to enable the caching on Windows?

There are 2 methods to activate the caching in Swiff Chart Generator on Windows:

- Programmatically by calling the caching API. This method enables you to individually select the scripts for which you need to use the caching system. See paragraph The Caching API for more information.
- From the Swiff Chart Generator Control Panel. This method enables you to setup the caching system for all the charts. Read The Swiff Chart Generator Control Panel for more information.

#### How to enable the caching on UNIX?

There are 2 methods to activate the caching in Swiff Chart Generator on UNIX systems:

- Programmatically by calling the caching API. This method enables you to individually select the scripts for which you need to use the caching system. See paragraph The Caching API for more information.
- From the configuration file swfchart.ini. This method enables you to setup the caching system for all the charts by simply editing a single file. Read Running Swiff Chart Generator on UNIX systems for more information.

#### The Caching API

The list below enumerates all the methods provided to manage the cache in your source code:

Method | Definition
--- | ---
UseCache | Enables or disables the caching system.
SetMaxCacheSize | If caching is enabled, specifies the maximum size of the cache in KB.
SetCacheName | If caching is enabled, specifies the name of the public cache relative to the web server root.
SetPrivateCacheDir | If caching is enabled, specifies the path of the private cache directory. This path is absolute, it is not relative to the web server. (optional)
ClearCache | If caching is enabled, this method forces the cache to be cleared.

IMPORTANT: Among the various methods provided by Swiff Chart Generator to generate a chart, some of them do not use the cache by default, others always require the use of the cache. The table below gives you the list of all the methods available to generate a chart and specifies for each of them if the cache is automatically used by Swiff Chart Generator or not.

Note: if you call a method which does not require the cache and if, in the same time, you want Swiff Chart Generator to use the cache for better performances, you must call the method UseCache to enable the cache or select Force cache in the Control Panel.

Method | Always Uses cache
--- | ---
GetHTMLTag | X
GetOutputLocation | X
ExportAsResponse |
ExportAsFile |
ExportAsBinary |

#### Examples.

- The VBScript code below illustrates the use of the cache when calling the ExportAsResponse method:

      <% @Language=VBScript %>
      <%
        Dim chart
        Set chart= Server.CreateObject("SwiffChartObject.ChartObj")

        chart.SetTitle "Movie Revenues"
        chart.SetCategoriesFromString "January;February;March"
        chart.SetSeriesValuesFromString 0, "187;110;159"

        chart.LoadStyle "pie\Geneva2"

        chart.SetCacheName "/charts_cache"
        chart.UseCache True
        chart.ExportAsResponse

        Set chart= Nothing

        Response.End
      %>

- However, since the method GetHTMLTag automatically uses the cache, the code below does not require the UseCache method to be called.

      <% @Language=VBScript %>
      <%
        Dim chart
        Set chart= Server.CreateObject("SwiffChartObject.ChartObj")

        chart.SetTitle "Movie Revenues"
        chart.SetCategoriesFromString "January;February;March"
        chart.SetSeriesValuesFromString 0, "187;110;159"

        chart.LoadStyle "pie\Geneva2"

        Response.Write chart.GetHTMLTag

        Set chart= Nothing
      %>

#### The Swiff Chart Generator Control Panel

The Swiff Chart Generator Control Panel enables you to fully configure the caching system. You can set all the required pathnames, the cache size as well as enable the cache for all the chart requests.

Read the Swiff Chart Control Panel page for a complete description of the dialog.