<?php include 'config.core.php'; include MODX_CORE_PATH . 'model/modx/modx.class.php'; $modx = new modX(); $modx->initialize('web'); $modx->setLogTarget(XPDO_CLI_MODE ? 'ECHO' : 'HTML'); $modx->setLogLevel(xPDO::LOG_LEVEL_INFO); $tstart = $modx->getMicroTime(); $chunk = $modx->getObject('modChunk', array('name' => 'testSpeed')); $chunk->setCacheable(false); for ($i = 0; $i < 1000; $i++) { echo $chunk->process(array('i' => $i)); } $tend = $modx->getMicroTime(); $modx->log(modX::LOG_LEVEL_INFO, sprintf("Processed 1000 chunks using getObject — %2.4f s\n", $tend - $tstart)); $tstart = $modx->getMicroTime(); $chunk = $modx->getParser()->getElement('modChunk', 'testSpeed'); for ($i = 0; $i < 1000; $i++) { echo $chunk->process(array('i' => $i)); } $tend = $modx->getMicroTime(); $modx->log(modX::LOG_LEVEL_INFO, sprintf("Processed 1000 chunks using modParser::getElement — %2.4f s\n", $tend - $tstart)); $tstart = $modx->getMicroTime(); for ($i = 0; $i < 1000; $i++) { echo $modx->getChunk('testSpeed', array('i' => $i)); } $tend = $modx->getMicroTime(); $modx->log(modX::LOG_LEVEL_INFO, sprintf("Processed 1000 chunks using getChunk — %2.4f s\n", $tend - $tstart)); exit();
Hi, after adding
What appears to be happening is that the tag is not changing with each new property value and so the result is that the chunk is always retrieved from the source cache.
$myChunkAsObject->_processed = false;
$chunkie = $modx->getObject('modChunk', array('name' => 'thumbTemplate')); foreach ($items as $item) { $itemArray = $item->toArray(); $itemArray['idx'] = $idx; (...) $output .= $chunkie->process($itemArray); $idx++; };
$tpl = 'chunk.name'; $tpl = $this->modx->getObject('modChunk', array('name' => $tpl)); //$tpl = $this->modx->getParser()->getElement('modChunk', $tpl); //$tpl->setCacheable(false); //$tpl->cache_type = 1; //$tpl->_processed = false; //$this->modx->log(modX::LOG_LEVEL_ERROR, '[' . $this->config['packagename'] . '] Chunk Object ' . print_r($tpl->toArray(),1)); foreach ( $records as $record ) { // parse tpl chunk if ( $record->getOne('Song') ) { $song = $record->getOne('Song')->toArray(); $record = $record->toArray(); $data = array_merge($record, $song); } else { $record = $record->toArray(); $data = $record; } // parse template chunk and return output, $tpl is a chunk name //$output .= $this->modx->getChunk($tpl, array( $output .= $tpl->process(array( 'timestamp' => $data['timestamp'], 'starttime' => $data['starttime'], 'audioartist' => $data['artistname'], 'audiotitle' => $data['songtitle'] )); }
<?php // A chunk named testSpeed is used with the following content: [[+i]] include 'config.core.php'; include MODX_CORE_PATH . 'model/modx/modx.class.php'; $modx = new modX(); $modx->initialize('web'); $modx->setLogTarget(XPDO_CLI_MODE ? 'ECHO' : 'HTML'); $modx->setLogLevel(xPDO::LOG_LEVEL_INFO); $tstart = $modx->getMicroTime(); $chunk = $modx->getObject('modChunk', array('name' => 'testSpeed')); $chunk->setCacheable(false); // This row is needed for ($i = 0; $i < 1000; $i++) { $chunk->_processed = false; // This row is needed echo $chunk->process(array('i' => $i)); } $tend = $modx->getMicroTime(); $modx->log(modX::LOG_LEVEL_INFO, sprintf("Processed 1000 chunks using getObject — %2.4f s\n", $tend - $tstart)); $tstart = $modx->getMicroTime(); $chunk = $modx->getParser()->getElement('modChunk', 'testSpeed'); $chunk->setCacheable(false); // This row is needed for ($i = 0; $i < 1000; $i++) { $chunk->_processed = false; // This row is needed echo $chunk->process(array('i' => $i)); } $tend = $modx->getMicroTime(); $modx->log(modX::LOG_LEVEL_INFO, sprintf("Processed 1000 chunks using modParser::getElement — %2.4f s\n", $tend - $tstart)); $tstart = $modx->getMicroTime(); for ($i = 0; $i < 1000; $i++) { echo $modx->getChunk('testSpeed', array('i' => $i)); } $tend = $modx->getMicroTime(); $modx->log(modX::LOG_LEVEL_INFO, sprintf("Processed 1000 chunks using getChunk — %2.4f s\n", $tend - $tstart)); exit();
$chunk->_processed = false;