3

Basically im trying to enable cell caching due to memory issues (keeps running out) its quite a large speadsheet. From what I have read online cell caching is a good way to go

From the examples I have found online it looks something like this

Cell caching and memory leak

stackoverflow - fix memory error

$oExcel = new PHPExcel();
$cacheMethod = PHPExcel_CachedObjectStorageFactory::cache_to_phpTemp;
$cacheSettings = array( 'memoryCacheSize' => '512MB');

PHPExcel_Settings::setCacheStorageMethod($cacheMethod,$cacheSettings);

The problem with the above is im not setting the excel object with the settings?

$oExcel->setCacheStorageMethod($cacheMethod,$cacheSettings); // this returns method not found error

I think im just initialising it wrong?

Community
  • 1
  • 1
Robbo_UK
  • 11,351
  • 25
  • 81
  • 117
  • So docs say `setCacheStorageMethod` is static? – Álvaro González Feb 01 '13 at 09:11
  • cant find reference to it in the docs. However found this is discussion. http://phpexcel.codeplex.com/discussions/234530 – Robbo_UK Feb 01 '13 at 09:24
  • With docs I meant wherever you read the `PHPExcel_Settings::setCacheStorageMethod($cacheMethod,$cacheSettings);` bit. It's displayed as static method of the `PHPExcel_Settings` class, not a regular method of the `PHPExcel` class. – Álvaro González Feb 01 '13 at 11:47
  • [Here you can find similar question with quite extensive answer](https://stackoverflow.com/a/3539125/2028547) that includes a working example of setCacheStorageMethod. Hope it helps! – MarcinWolny Feb 01 '13 at 09:26

1 Answers1

10

It's described in section 4.2.1 of the developer documentation: the section entitled "Cell Caching"; and you need to set the cell cache before you instantiate or load your PHPExcel object.

setCacheStorageMethod() is not a method of the PHPExcel class, as you're trying to use in this line:

$oExcel->setCacheStorageMethod($cacheMethod,$cacheSettings); 

use

$cacheMethod = PHPExcel_CachedObjectStorageFactory::cache_to_phpTemp;
$cacheSettings = array( 'memoryCacheSize' => '512MB');
PHPExcel_Settings::setCacheStorageMethod($cacheMethod,$cacheSettings);

$oExcel = new PHPExcel();

and the new PHPExcel object will automatically use the configured cache setting (ie phptemp)

Mark Baker
  • 209,507
  • 32
  • 346
  • 385
  • 1
    For the above to work does the new initializing of new PHPExcel() have to happen after the setCache static method has been ran. I'm a bit confused how the object is aware of the new setting. – Robbo_UK Feb 01 '13 at 09:37
  • 1
    Yes, afterwards.... the PHPExcel object constructor reads the cache settings that you have defined previously – Mark Baker Feb 01 '13 at 09:39