Documentation:

Back
phpchartPlus Documentation
Tsiavos Chris <[email protected]>
Date: 18-Feb-2005
License: GPL
3.3.2 Using the CacheToFile Strategy
To use the CacheToFile Strategy you have to follow 3 steps
1. Include the appropriate file
2. Initialize the CacheToFile Strategy class
3. Strategize the phpchartPlus instance with the CacheToFile Strategy instance passing as a parameter the validity period (in minutes) of the cached copy.
code portion from file: "Examples/example.php"
include("../Sources/phpchartPlus.php");
include("../Sources/CacheToFile_Strategy.php");
include("../Sources/PEARDBData_Strategy.php");
include("../Sources/XMLConfig_Strategy.php");
 
$DataParams=array("DB_Type"=>"",
                  "DB_Username"=>"",
                  "DB_Passwd"=>"",
                  "DB_Host"=>"",
                  "DB_Name"=>"",
                  "Field_GroupName"=>"",
                  "Field_ItemName"=>"",
                  "Field_ItemValue"=>"");
 
$ConfigParams=array("filename"=>"../Data/phpchartplus.conf.xml"); 
 
$DataStrategy=new PEARDBData_Strategy();
$ConfigStrategy=new XMLConfig_Strategy();
$CacheStrategy=new CacheToFile_Strategy(); 

$im=new phpchartPlus();
                   
try
{
$im->DataParser_->strategize($DataStrategy,$DataParams);
$im->DataParser_->parse(array("Query"=>"SELECT * FROM my_table"));
}
   catch (DataParser_Exception $e) 
   {
   print $e->getMessage();
   exit();
   }
   catch (DataStrategy_Exception $f) 
   {
   print $f->getMessage();
   exit();
   }
   
try
{
$im->ConfigParser_->strategize($ConfigStrategy,$ConfigParams);
$im->ConfigParser_->parse();
}
   catch (ConfigParser_Exception $e) 
   {
   print $e->getMessage();
   exit();
   }
   catch (ConfigStrategy_Exception $f) 
   {
   print $f->getMessage();
   exit();
   } 
   
try
{
$im->get_Instance();
}
   catch (ImageSupport_Exception $e)
   {
     print $e->getMessage();
     exit();
   }
   catch (FontSupport_Exception $f)
   {
     print $f->getMessage();
     exit();
   }
   
$im->Chart_->set_CachingStrategy($CacheStrategy,2); 
//Cache for 2 minutes 
$im->Chart_->draw_Chart();              
 

 
Hosted by www.Geocities.ws

1