$chunk = $modx->getObject('modChunk',array(
'name' => $spfresponseTpl
));
if ($chunk == null) {
die ($modx->lexicon('no-template'). $spfresponseTpl);
}
return ($chunk->process());
Hmmm, not sure if it is expected, and will certainly take some getting used to, but the cache control and flexibility gained IMO should be worth it. I think it’s more natural for anything cacheable within non-cacheable content to remain cacheable rather than being forced to non-cacheable automatically, especially now that all Elements and [most] Tags can be non-cacheable explicitly.
On a cached page, when an uncached snippet call returns a chunk with $chunk->process(), it will return a cached version of the chunk in Revolution.
Maybe this is expected, but it caught me by surprise (and I don’t want to admit how many hours it took to figure it out).
If the chunk were placed in a page with tags, it could be marked as uncached. Is there an equivalent for grabbing it uncached in an uncached snippet? Making the resource uncached solved it, but I expected it to take on the caching of the snippet that retrieved it.
This could make for some very weird behavior in uncached snippets on cached pages.
<?php
$chunk = $modx->getObject('modChunk',array(
'name' => $spfresponseTpl
));
$chunk->_cacheable = false;
return ($chunk->process());
?><?php
$chunk = $modx->getObject('modChunk',array('name' => $spfresponseTpl));
if ($chunk->isCacheable()) {
$chunk->setCacheable(false);
}
?>$chunk->_cacheable = false;

FWIW, placeholders can never be cached technically; this behavior is only because you are delaying the processing of the placeholder tags by introducing the non-cacheable token ( ! ) to them. They are not processed until all cacheable content (which is reachable through cacheable processing) has been processed. However, when loaded from the Resource cache file, any tags that were processed as cacheable before the Resource was cached will be cached along with it, and this, when loaded from the cache, the chunk tag would have been loaded from the elementCache, since it is cacheable, but the non-cacheable placeholders tags would not have been removed since they are processed in the final step and only stored in the output which is generated by the additional non-cacheable processing performed in modResponse::outputContent().
As I wrote in the post above, the real problem in this case was with getting cached versions of the placeholders. I was glancing at the listing of the new Revolution tags pushpinned above my screen and noticed the line: "Anything can be cached ..."
I changed the placeholders to [[!+placeholder]] and the problem seems to be solved regardless of the cacheable status of the chunk they are in.
My complements to the chef !!
I think this makes the issue of un-caching chunks somewhat less critical. It’s still important for people who want to specify which chunk is used on the fly, but in many cases, just having the placeholders fresh is perfect.IMO, passing placeholders intended for a chunk directly to it as properties, e.g. $modx->getChunk(’MyChunk’, array(’placeholder1’ => ’value1’)) is the best approach, as this ensures the scope of those placeholders is only that chunk (or anything contained in it). This approach will not work with the delayed global non-cacheable placeholder idea however, since the placeholders will only technically be in place for the scope of the chunk and not beyond it, but this completely depends on how you set up the placeholders and when. For chunks that are called repetitively in the same page, passing them as properties is the best way.
I believe so; you can see everything that was cached by looking at the Resource cache file. You would look in core/cache/web/resources/1.php for the Resource with id 1 in the default web context.
Just out of curiosity, in this case where the page is cached, the snippet is called uncached, the chunk is cached and the placeholders are uncached. Is the chunk really coming from the cache?
FWIW, placeholders can never be cached technically; this behavior is only because you are delaying the processing of the placeholder tags by introducing the non-cacheable token ( ! ) to them. They are not processed until all cacheable content (which is reachable through cacheable processing) has been processed. However, when loaded from the Resource cache file, any tags that were processed as cacheable before the Resource was cached will be cached along with it, and this, when loaded from the cache, the chunk tag would have been loaded from the elementCache, since it is cacheable, but the non-cacheable placeholders tags would not have been removed since they are processed in the final step and only stored in the output which is generated by the additional non-cacheable processing performed in modResponse::outputContent().
I get the first sentence here, but the second one came close to actually melting my brain. If I’m right above and the chunk is being cached after the placeholders are replaced, passing placeholders in the getChunk call wouldn’t work since there would be no placeholders in the returned object (unless I set _chacheable to false -- which solves the problem even without the second argument). I guess I should try it to make sure.
IMO, passing placeholders intended for a chunk directly to it as properties, e.g. $modx->getChunk(’MyChunk’, array(’placeholder1’ => ’value1’)) is the best approach, as this ensures the scope of those placeholders is only that chunk (or anything contained in it). This approach will not work with the delayed global non-cacheable placeholder idea however, since the placeholders will only technically be in place for the scope of the chunk and not beyond it, but this completely depends on how you set up the placeholders and when. For chunks that are called repetitively in the same page, passing them as properties is the best way.

It’s literally added to the placeholder array during processing of the chunk and removed after processing, so a chunk that is cached will never set the placeholders from the properties when loaded from the cache.
If I only pass one placeholder name and value that way, what’s the effect on the other placeholders in the chunk if the chunk is cached? Do they remain cached?
You could do that, as long as those placeholder values were not set by properties passed to the chunk. This would not work, since these local property placeholders are removed after processing and any colliding placeholders in the previous scope restored. So [[!+placeholder]] would basically prevent it from being processed in the local scope of the chunk, even when uncached. Using the non-cacheable token (i.e. ! ) always delays processing until all cacheable processing is completed by either the Template attached to a Resource, or the Content of a Resource itself if no Template is specified.
Ultimately, I’d like to have some placeholders in a chunk cached and others not. There could easily be a large cached chunk with lots of placeholders that should be cached and only one or two that need to be uncached. Using [[!+placeholder]] would be a nice easy way of accomplishing that in a cached chunk. Is that a possible scenario?
I must be misunderstanding this because what I see seems to contradict this. My chunk is in a cached page and should be cached by default (causing my original problem). But it *does* set the placeholder from the properties sent in the getChunk() call even though I don’t use _cachable=false or the ! token in the placeholder tags.
Quote from: BobRay at Oct 20, 2008, 06:16 PMIt’s literally added to the placeholder array during processing of the chunk and removed after processing, so a chunk that is cached will never set the placeholders from the properties when loaded from the cache.
If I only pass one placeholder name and value that way, what’s the effect on the other placeholders in the chunk if the chunk is cached? Do they remain cached?
Quote from: BobRay at Oct 20, 2008, 06:16 PMYou could do that, as long as those placeholder values were not set by properties passed to the chunk. This would not work, since these local property placeholders are removed after processing and any colliding placeholders in the previous scope restored. So [[!+placeholder]] would basically prevent it from being processed in the local scope of the chunk, even when uncached. Using the non-cacheable token (i.e. ! ) always delays processing until all cacheable processing is completed by either the Template attached to a Resource, or the Content of a Resource itself if no Template is specified.
Ultimately, I’d like to have some placeholders in a chunk cached and others not. There could easily be a large cached chunk with lots of placeholders that should be cached and only one or two that need to be uncached. Using [[!+placeholder]] would be a nice easy way of accomplishing that in a cached chunk. Is that a possible scenario?