3

Let's suppose I have a Php function like this:

private function verification($isXLSFile = false) {

    if ($isXLSFile) {
        $this->parseXLSFile();
    }else {
        $parsedCSVArr = $this->getCSVarr();
        Zend_Registry::get('VMMS_ZEND_CACHE')->save($parsedCSVArr, $this->getXLSCacheName());
        Zend_Registry::get('VMMS_ZEND_CACHE')->save($isXLSFile, $this->getXLSCacheName());
    }
}

And then I call another function checking the CACHE like this:

private function process(){
    Logger::info("EnterDataMassUpload - Start Process...");
    if (($parsedCSVArr = Zend_Registry::get('VMMS_ZEND_CACHE')->load($this->getXLSCacheName())) === false) {
        $this->verification();
        return;
    }
    //if XLS file it reads the lines for each sheet.
    if ($isXLSFile == true) {
        $i=0;
        //make sure there's no duplicated row
        $parsedCSVArr = array_unique($parsedCSVArr, SORT_REGULAR);
        foreach($parsedCSVArr as $sheetIndex=>$arr){
            foreach ($arr as $k=>$line) {
                $this->processLine($line, $k);
                $i++;
            }
        }
    } else { //for a CSV file
        foreach($parsedCSVArr as $k=>$line){
            $this->processLine($line, $k);
        }
    }
    // ...

As you can see, I'm trying to save 2 variables in the same place to read it in the function process(). Do you know why my flag is not working? I mean.. can I save two variables in the same place:

 Zend_Registry::get('VMMS_ZEND_CACHE')->save($parsedCSVArr, $this->getXLSCacheName());
 Zend_Registry::get('VMMS_ZEND_CACHE')->save($isXLSFile, $this->getXLSCacheName());
Florent
  • 12,310
  • 10
  • 49
  • 58
sergioviniciuss
  • 4,596
  • 3
  • 36
  • 50
  • 1
    nope, each key must be unique, just like variables, otherwise you will overwrite the old one, try saving an array of your variables – max4ever Sep 13 '12 at 16:19

1 Answers1

3

Why don't you save it under two different names ?

Else, you can save under the same name the two variables using serialization.

Zend_Registry::get('VMMS_ZEND_CACHE')->save(serialize(array('parsedCSVArr' => $parsedCSVArr, 'isXLSFile' => $isXLSFile)), $this->getXLSCacheName());

Then, in the process function get the cache result and :

$cacheResult['parsedCSVArray'];
$cacheResult['isXLSFile'];
Julien Fouilhé
  • 2,583
  • 3
  • 30
  • 56