public function cache()
{
/* Sample use
---------------------------------------------------------
{exp:stash:cache}
...
{/exp:stash:cache}
*/
// process as a static cache?
if ($this->EE->TMPL->fetch_param('process') == 'static') {
return $this->static_cache($this->EE->TMPL->tagdata);
}
// Is this page really cacheable? (Note: allow all request types to be cached)
if (!$this->_is_cacheable(FALSE)) {
self::$_nocache = FALSE;
// remove {stash:nocache} pairs
$this->EE->TMPL->tagparams['replace'] = 'yes';
$this->EE->TMPL->tagparams['save'] = 'no';
// disable caching
} else {
$this->EE->TMPL->tagparams['save'] = 'yes';
}
// Unprefix common variables in wrapped tags
if ($unprefix = $this->EE->TMPL->fetch_param('unprefix')) {
$this->EE->TMPL->tagdata = $this->_un_prefix($unprefix, $this->EE->TMPL->tagdata);
}
// default name for cached items is 'cache'
$this->EE->TMPL->tagparams['name'] = $this->EE->TMPL->fetch_param('name', 'cache');
// cached items are saved to the template bundle by default, allow this to be overridden
$this->EE->TMPL->tagparams['bundle'] = $this->EE->TMPL->fetch_param('bundle', 'template');
// by default, parse on both set and get (i.e. so partial caching is possible)
$this->EE->TMPL->tagparams['parse_stage'] = $this->EE->TMPL->fetch_param('parse_stage', 'both');
// key_name format for cached items is @URI:context:name, where @URI is the current page URI
// thus context is always @URI, and name must be set to context:name
if ($context = $this->EE->TMPL->fetch_param('context', FALSE)) {
$this->EE->TMPL->tagparams['name'] = $this->_parse_context($context . ':') . $this->EE->TMPL->tagparams['name'];
}
// context parameter MUST be set to the page URI pointer
$this->EE->TMPL->tagparams['context'] = '@URI';
// set a default parse depth of 4
$this->EE->TMPL->tagparams['parse_depth'] = $this->EE->TMPL->fetch_param('parse_depth', 4);
// don't replace the variable by default
$this->EE->TMPL->tagparams['replace'] = $this->EE->TMPL->fetch_param('replace', 'no');
// set a default refresh of 0 (never)
$this->EE->TMPL->tagparams['refresh'] = $this->EE->TMPL->fetch_param('refresh', 0);
// mandatory parameter values for cached items
$this->EE->TMPL->tagparams['scope'] = 'site';
$this->EE->TMPL->tagparams['parse_tags'] = 'yes';
$this->EE->TMPL->tagparams['parse_vars'] = 'yes';
$this->EE->TMPL->tagparams['parse_conditionals'] = 'yes';
$this->EE->TMPL->tagparams['output'] = 'yes';
$this->process = 'end';
// re-initialise Stash with the new params
$this->init();
// permitted parameters for cache
$reserved_vars = array('name', 'context', 'scope', 'parse_stage', 'save', 'refresh', 'replace', 'parse_tags', 'parse_depth', 'parse_vars', 'parse_conditionals', 'output', 'bundle', 'prefix', 'trim', 'strip_tags', 'strip_curly_braces', 'strip_unparsed', 'compress', 'backspace', 'strip');
// cache / retreive the variables
$this->_run_tag('set', $reserved_vars);
// Is partially cached content possible? We'll need to make sure it's parsed before returning to the template
if ($this->EE->TMPL->tagparams['parse_stage'] == 'both' || $this->EE->TMPL->tagparams['parse_stage'] == 'get') {
$this->_parse_sub_template($this->parse_tags, $this->parse_vars, $this->parse_conditionals, $this->parse_depth);
}
return $this->EE->TMPL->tagdata;
}