SourceForge.net  |  Sunyday.net
Last release: 1.27d
a PHP Class to build Charts
pChart 2.x is born, you can start moving your script to this new version. The new website is at www.pchart.net.
Overview  |  Screenshots  |  Download  |  Add-ons  |  Demonstration  |  Support  |  :: Documentation ::
Documentation Contents
Overview
Class definition
pChart.class
pData.class
pCache.class
FAQ
Digging with pChart
Basic Examples
Advanced Examples
pCache.class - Compute one time, spread everywhere

Saving web server speed and CPU is something that matter to us. We've created the pCache class to help you dealing with the fact that a chart can be computed once and displayed many times by different users. The pCache class can be used to simplify server side cache management. In green, the normal process : retrieve data, compute and display, in orange the cost saving path, retrieve the data, check if we have already computed it and display it!


An example of how to use the pCache class can be found here. You'll find bellow a short summary of all the embeded function and their related parameters. Functions categories :

Class initialisation
  pCache($CacheFolder="Cache/")
Cache management
  IsInCache($ID,$Data,$Hash="")
  GetFromCache($ID,$Data)
  WriteToCache($ID,$Data,$Picture)
  DeleteFromCache($ID,$Data)
  DeleteFromCache()

pCache
void pCache($CacheFolder="Cache/")

This function create a new pCache object. This object will be used to access the processed data cache. You can optionnaly specify the cache folder to use.
  // This will create a new pCache object with default cache folder
  $MyCache = new pCache();

  // This will create a new pCache object setting the cache folder to /tmp/
  $MyCache = new pCache("/tmp/");
 
IsInCache
void IsInCache($ID,$Data,$Hash="")

This function can be used to check if the dataseries you're currently working on has already been computed and is stored in the cache. This will return TRUE or FALSE. This function accept a Dataset as first parameter, see the pData class for more informations. ID is used to uniquely indentify your drawing script.
  // This will return TRUE if this chart has already been rendered
  $MyCache->IsInCache("Pic#1",$DataSet->GetData());
 
GetFromCache
void GetFromCache($ID,$Data)

This function will retrieve a chart from the cache if it already exists. The picture will be sent to the browser the same way as if you're invoking the Stroke() function of the pChart class. ID is used to uniquely indentify your drawing script. If the cache can be used, the picture will be send to the browser the same way then calling the Stroke() function, no other lines of your script will be processed after this line.
  // This will check the cache for an existing copy and Stroke it.
  $MyCache->GetFromCache("Pic#1",$DataSet->GetData());
 
WriteToCache
void WriteToCache($ID,$Data,$Picture)

Use this function to make a copy of the rendered chart to your cache folder. This function is mandatory for the pCache to work properly. This function must be called at the end of your rendering script before the Stroke() or Render() call. ID is used to uniquely indentify your drawing script. $Data is the dataset used to draw the chart. $Picture is the name of the pChart object containing the chart.
  // This will save the rendered picture in the cache folder.
  $MyCache->WriteToCache("Pic#1",$DataSet->GetData(),$Picture);
 
DeleteFromCache
void DeleteFromCache($ID,$Data)

This function can be used to delete the cached copy of the chart ( if it exists ). ID is used to uniquely indentify your drawing script.
  // This will delete any cached copy of this chart.
  $MyCache->DeleteFromCache("Pic#1",$DataSet->GetData());
 
ClearCache
void ClearCache()

Calling this function will clear the cache folder.
  // This will cleanup the cache folder.
  $MyCache->ClearCache();
 
Last updated on 06/17/2008