A very simple chart example, with a difference: You may have noticed that almost all the demonstration JSPs write an image into the "cache" directory. If you're on a high-volume server, the cache directory will quickly fill with small image files. |
By setting the property "useCacheCleaner" to "true", and setting some other properties, you can start a thread that will empty the cache directory periodically.
//activate the cache cleaner and set a few properties chart.setProperty("useCacheCleaner", "true"); chart.setProperty("cacheCleanerDirectory", application.getRealPath("images/KavaChartImages/")); // this must match the writeDirectory // be careful - almost everything in that directory will be erased!!! chart.setProperty("cacheCleanerInterval", "10"); // every 10 minutes, CacheCleaner will run chart.setProperty("cacheCleanerExpirationTime", "5"); //everything older than five minutes will be deleted
Whenever the KavaChart cache cleaner runs, it clears all files older than a specified time from the cache directory. The run interval and the expiration time will vary, depending on your application. Some applications can reuse charts for days, or even months. Others require more frequent maintenance. This example runs every ten minutes. If you examine the cache directory in another 10 minutes, you'll see that all image files older than 5 minutes have been removed.
Since you don't want to start a new thread for every image, KavaChart uses a single CacheCleaner for all charts. If you're using multiple cache directories, start CacheCleaner independently, rather than using chart properties.
Note: Another approach is to use ProServe chart tags, which will stream images to your page without saving them on the server.