-
- 956 Posts
I’ve used runSnippet() several times, always uncached. o_O
-
- 4,213 Posts
What do you mean? as far as I know, it’s just the opposite, i.e. runSnippet always runs (eval with passed parameters) the snippet in "not cached mode".
If you mean that cache code what you see in the wiki, it checks if the snippet code is found on cache already, if it’s not, the code is retrieved from db. But even if the code itself is found from cache, it doesn’t mean that the snippet runs in cached mode. The code is then run in eval in both options and with the passed parameters. Then the output from the eval is returned, i.e. the snippet output is not retrieved from cache.
"He can have a lollipop any time he wants to. That's what it means to be a programmer."
-
- 134 Posts
The snippet that I was running from runSnippet() was Ditto. I was using it to pull in some random content (&randomize=`1`) for a web page from among several possibilities. But the same content would always load. MODx had cached the result of the snippet when it was run the first time. It would not change the content until the cache was cleared.
The page had "Cacheable" checked (turned on). Now, I could uncheck that box, but that slows the page WAY down. I want only the snippet to be uncached. It seems that the call to the snippet using runSnippet() bypasses the condition that lets me choose whether to cache the result of the snippet as part of the page or to always run the snippet even though the rest of the page is cached.
Am I to understand that you are using Ditto to insert random header content in dynamic pages? That really is not an efficient solution IMHO, unless you are caching the content. A component meant to do something like this directly would be much more prudent and less resource intensive. Ditto is a very flexible snippet, and you can accomplish a lot of things this way, but that does not mean it is the best way to do it or that there is not going to be a huge overhead for using a generalized snippet for a specific requirement.
-
- 134 Posts
That’s fair enough. Even so, the issue of not being able to run the snippet uncached remains.
-
- 134 Posts
The runSnippet() function is being called from a snippet that is called from inside of a template. The template contains a line more or less like this:
[[mySnippet]]
and "mySnippet" contains the call to the runSnippet() function. As you can see, the call to the snippet above is cached, which is actually what I want, but I guess I can’t put a reference to an uncached item within a cached item. Is that what it boils down to?