Difference between revisions of "JCacheView/get"
From Joomla! Documentation
< API15:JCacheView
(New page: ===Description===
Get the cached view data
<span class="editsection" style="font-size:76%;">
<nowiki>[</nowiki>Edit Descripton<nowiki>]</nowiki>
</span...) |
m (removing red link to edit, no existant pages) |
||
(One intermediate revision by one other user not shown) | |||
Line 3: | Line 3: | ||
<span class="editsection" style="font-size:76%;"> | <span class="editsection" style="font-size:76%;"> | ||
− | <nowiki>[< | + | <nowiki>[<! removed edit link to red link >]</nowiki> |
</span> | </span> | ||
− | + | <! removed transcluded page call, red link never existed > | |
===Syntax=== | ===Syntax=== | ||
Line 17: | Line 17: | ||
!Description | !Description | ||
|- | |- | ||
− | | | + | | &$view |
| | | | ||
| $view The view object to cache output for | | $view The view object to cache output for | ||
Line 141: | Line 141: | ||
<span class="editsection" style="font-size:76%;"> | <span class="editsection" style="font-size:76%;"> | ||
− | <nowiki>[< | + | <nowiki>[<! removed edit link to red link >]</nowiki> |
</span> | </span> | ||
− | + | <! removed transcluded page call, red link never existed > | |
===Examples=== | ===Examples=== | ||
Line 156: | Line 156: | ||
format= ,,, | format= ,,, | ||
</dpl> | </dpl> | ||
+ | [[Category:Archived pages API15]] |
Revision as of 08:51, 12 May 2013
The "API15" namespace is an archived namespace. This page contains information for a Joomla! version which is no longer supported. It exists only as a historical reference, it will not be improved and its content may be incomplete and/or contain broken links.
Description[edit]
Get the cached view data
[<! removed edit link to red link >]
<! removed transcluded page call, red link never existed >
Syntax[edit]
get(&$view, $method, $id=false)
Parameter Name | Default Value | Description |
---|---|---|
&$view | $view The view object to cache output for | |
$method | $method The method name of the view method to cache output for | |
$id | false | $group The cache data group |
Returns[edit]
boolean True if the cache is hit (false else)
Defined in[edit]
libraries/joomla/cache/handler/view.php
Importing[edit]
jimport( 'joomla.cache.handler.view' );
Source Body[edit]
function get( &$view, $method, $id=false )
{
global $mainframe;
// Initialize variables
$data = false;
// If an id is not given generate it from the request
if ($id == false) {
$id = $this->_makeId($view, $method);
}
$data = parent::get($id);
if ($data !== false) {
$data = unserialize($data);
$document = &JFactory::getDocument();
// Get the document head out of the cache.
$document->setHeadData((isset($data['head'])) ? $data['head'] : array());
// If the pathway buffer is set in the cache data, get it.
if (isset($data['pathway']) && is_array($data['pathway']))
{
// Push the pathway data into the pathway object.
$pathway = &$mainframe->getPathWay();
$pathway->setPathway($data['pathway']);
}
// If a module buffer is set in the cache data, get it.
if (isset($data['module']) && is_array($data['module']))
{
// Iterate through the module positions and push them into the document buffer.
foreach ($data['module'] as $name => $contents) {
$document->setBuffer($contents, 'module', $name);
}
}
// Get the document body out of the cache.
echo (isset($data['body'])) ? $data['body'] : null;
return true;
}
/*
* No hit so we have to execute the view
*/
if (method_exists($view, $method))
{
$document = &JFactory::getDocument();
// Get the modules buffer before component execution.
$buffer1 = $document->getBuffer();
// Make sure the module buffer is an array.
if (!isset($buffer1['module']) || !is_array($buffer1['module'])) {
$buffer1['module'] = array();
}
// Capture and echo output
ob_start();
ob_implicit_flush( false );
$view->$method();
$data = ob_get_contents();
ob_end_clean();
echo $data;
/*
* For a view we have a special case. We need to cache not only the output from the view, but the state
* of the document head after the view has been rendered. This will allow us to properly cache any attached
* scripts or stylesheets or links or any other modifications that the view has made to the document object
*/
$cached = array();
// View body data
$cached['body'] = $data;
// Document head data
$cached['head'] = $document->getHeadData();
// Pathway data
$pathway = &$mainframe->getPathWay();
$cached['pathway'] = $pathway->getPathway();
// Get the module buffer after component execution.
$buffer2 = $document->getBuffer();
// Make sure the module buffer is an array.
if (!isset($buffer2['module']) || !is_array($buffer2['module'])) {
$buffer2['module'] = array();
}
// Compare the second module buffer against the first buffer.
$cached['module'] = array_diff_assoc($buffer2['module'], $buffer1['module']);
// Store the cache data
$this->store(serialize($cached), $id);
}
return false;
}
[<! removed edit link to red link >] <! removed transcluded page call, red link never existed >
Examples[edit]
<CodeExamplesForm />