Cell caching not exhibiting expected performance changes

Topics: Developer Forum
Aug 1, 2011 at 7:43 AM

I am using version 1.7.6 of PHPExcel.

I am using PHPExcel to convert data from a MySQL DB to the .xls format.

My code is at the bottom. My primary question is: Is cell caching only have an effect when reading a file in from disk? As I am timing and measuring memory usage I see very negligible  differences between using cell-caching and not using cell-caching. I've read the documentation in the PHPExcel Word files included in the source file package but they don't seem to give a very thorough example. What would be helpful is a an example in the examples section that show people how to use cell caching. I can provide actual metrics if that is helpful; I suspect that I am using the API incorrectly.



$startTime = time();
$startMMB = memory_get_peak_usage(true)/(1024*1204);
$cacheMethod = PHPExcel_CachedObjectStorageFactory::cache_to_discISAM;

$cacheMethod = PHPExcel_CachedObjectStorageFactory::cache_to_phpTemp;
$cacheSettings = array('memoryCacheSize' =>'1MB');
PHPExcel_Settings::setCacheStorageMethod($cacheMethod, $cacheSettings);
$exportDoc = new PHPExcel();

for ($i = 1; $i <= $numSurveys; $i++){
      $surveyData = $this->_retrieveSurveyData($surveyIndices[$i-1], $agencyID, $includeAnon, $sortBy);
      $exportDoc = $this->_formatSpreadsheet($exportDoc, $surveyData['docData'], $surveyData['docHeader']);	    

      // Rename sheet
  $usedTime = time() - $startTime;
  $usedMem = (memory_get_peak_usage(true)/(1024*1204)) - $startMMB;
  $t = sprintf("%3ds", $usedTime);
  $m = sprintf("%.2fMB", $usedMem);
  $d = date('H:i:s');
  error_log("[$d] time:$t memoryUsed: $m\n", 3, "/source/epwbst/phpexcel.txt");

$docWriter = PHPExcel_IOFactory::createWriter($exportDoc, 'Excel5');

$usedTime = time() - $startTime;
$usedMem = (memory_get_peak_usage(true)/(1024*1204));
$t = sprintf("%3ds", $usedTime);
$m = sprintf("%.2fMB", $usedMem);
$d = date('H:i:s');        
error_log("[$d] total time:$t total memory: $m\n", 3, "source/epwbst/phpexcel.txt");