Hi,
I have a snippet which is called like this :
[[!loadTemplate? &template=`text`]]
In snippet I do this:
I'm trying to cache a news page depending on mobile/desktop device.
//if(!$deviceType) $deviceType = 'desktop';
$cacheManager = $modx->getCacheManager();
$lifetime = 3600*24*7; // in seconds
require_once 'core/components/sanz/Mobile_Detect.php';
$detect = new Mobile_Detect;
if ( $detect->isMobile() || $_GET['browser'] == 'mobile') {
$deviceType = 'mobile';
} else if( $detect->isTablet() ){
$deviceType = 'mobile';
} else {
$deviceType = 'desktop';
}
$key = sha1(json_encode(array( $_GET,
$deviceType
,$_SERVER['REQUEST_URI']
)));
if (!$resu = $cacheManager->get($key)) {
$resu = $modx->parseChunk('tpl_'.$template.'--'.$deviceType);
$resu.='<!--loadTemplate/'.time().'/'.$key.'-->';
$cacheManager->set($key ,
$resu,
$lifetime
);
}
return $resu.'<!--loadTemplate'.$deviceType.'-->';
It works. But down the hierarchy of chunks there is one thing I do not need to cache - block showing visitor's geoposition.
I print it using two snippets :
{$_modx->runSnippet('!renderGeoCategoryNews', ['category'=> $_modx->runSnippet('!getCurrentLocation') ])}
Unfortunately,
inside renderGeoCategoryNews() caches and does not change.
Why?
[ed. note: iampublic last edited this post 7 years, 1 month ago.]