Stash
ExpressionEngine 2, ExpressionEngine 3, ExpressionEngine 4, ExpressionEngine 5, ExpressionEngine 6
Back to this add-on's main page
View Other Add-ons From Mark Croxton
{exp:stash:cache} parsing and caching contents of nocache w/o deep enough parse_depth.
Support Request
Fusionary
|
Posted: 10 February 2014 11:46 AM |
|
|
|
Everything is here:
https://gist.github.com/timkelty/8918067
A bit of a trip down the rabbit hole, but I’m trying to cache the whole template output, except for the contents of `views:highlights:heart-links.html`.
Without `parse_depth=“5”` on the outer cache tag, the contents of my `{stash:nocache}` are cached as part of the created cache, and therefore no longer dynamic.
With `parse_depth=“5”` it works, but should this be necessary?
|
|
|
Mark Croxton
|
Posted: 10 February 2014 12:25 PM |
# 1
|
|
Developer
|
It’s good to be make your code reusable but important not to forget that those partial chunks of code, should, as far as possible, not be contingent on other chunks of code, which is essentially the principle of decoupling, or ‘separation of concerns’.
In your templates you have an embed ‘views:highlights:cards’ which loads ‘views:highlights:card’ which loads ‘views:highlights:heart-links’. These are all clearly dependent on one another and breaking them up into three complicates your scheme rather than helps it.
As to the problem with stash:nocache being parsed, I’d say this is likely the result of the parse_stage=“both” on the embed tag which includes it. As you already have that on your outermost stash:cache tag you don’t want it on any child tag that the outer tag processes, since the parse_stage is relative to the parent (be it an embed, or stash:cache).
|
|
|
Fusionary
|
Posted: 10 February 2014 12:40 PM |
# 2
|
|
|
I know it might appear from this example that I’m “overdoing it”, but anything that is broken up is because its being used elsewhere.
In this case you’ll notice I’m doing alot of `process=“start” parse=“no”`, so the breaking up of things is largely to reuse markup. It could just as well be a EE snippet.
|
|
|
Fusionary
|
Posted: 10 February 2014 01:36 PM |
# 3
|
|
|
Does it make more sense to put parse_stage=“yes” on the outer tag, or to remove it and try to get it working by adding the param to the embeds that require it (ones with nocache tags)?
|
|
|
Mark Croxton
|
Posted: 10 February 2014 01:47 PM |
# 4
|
|
Developer
|
You need parse_stage=“both” on the outermost {exp:stash:cache} only because what you want to end up with is a flattened template (your cached page) with only some parts of it remaining dynamic. You don’t want to parse_stage=“both” any of your nested embeds because that means stash will fully parse the embeds before passing the tagdata back up to the parent tag.
It will really help you to look at the variable generated by {exp:stash:cache} and see which bits are remaining unparsed. You will find variables like {entry_id} inside {stash:nocache} regions are remaining unparsed but the code that sets the value of {entry_id} is parsed therefore the value never get’s set when the cache is retrieved. Partial caching can trip you up like that. It’s worth noting you can do this kind of thing to un-escape content:
{stash:nocache} ... {exp:remember_me:get entry_id="{/stash:nocache}{stash:entry_id}{stash:nocache}"} ... {/stash:nocache}
|
|
|
Fusionary
|
Posted: 10 February 2014 05:00 PM |
# 5
|
|
|
It seems like you’re right, in that `{entry_id}` and `{stash:entry_id}`, are unparsed as long as they’re inside of `{stash:nocache}`.*
So is there a different approach around this? Basically I have an outer loop (get_list) and for each item I have a bit of un-cachable content that is determined by the entry_id column of the list.
Seems like I’ve tried everything…
* correction - {stash:entry_id} is parsed within {stash:nocache}, but as the same value, over and over again.
|
|
|
Fusionary
|
Posted: 10 February 2014 05:16 PM |
# 6
|
|
|
I’ve even tried wrapping the entire cards.html template in {stash:nocache}, but the cache var always has the output already parsed and therefore not dynamic…
|
|
|
Fusionary
|
Posted: 10 February 2014 05:25 PM |
# 7
|
|
|
Another thing worth mentioning: it seems that if you ee comment out {stash:nocache} lines from your template, they don’t actually get removed, which was confusing me for a while!
|
|
|
Mark Croxton
|
Posted: 10 February 2014 06:43 PM |
# 8
|
|
Developer
|
Are you using Stash 2.4.8? Did you remove parse_stage=“both” from your embed tag?
|
|
|
Fusionary
|
Posted: 10 February 2014 08:20 PM |
# 9
|
|
|
Yep, 2.4.8. I removed parse_stage=“both” from the embed, so it is now only on the outer {exp:stash:cache} tag
|
|
|
Fusionary
|
Posted: 10 February 2014 10:01 PM |
# 10
|
|
|
So, even with a completely simplified template, I can’t figure out any way to get content from outside `{stash:nocache}` to parse within it.
|
|
|
Fusionary
|
Posted: 10 February 2014 10:28 PM |
# 11
|
|
|
Well I’ve managed to get my simplified template working, using the escaping example you posted.
I haven’t managed to get it to work in my real template though. It just ends up parsing and caching what’s in the nocache tag…
|
|
|
Fusionary
|
Posted: 11 February 2014 12:29 AM |
# 12
|
|
|
WOW.
This gist is updated, and I now have it working: https://gist.github.com/timkelty/8918067
I had to:
* remove the parse_stage=“both” on the inner template
* remove parse_tags=“yes” on the set_list tag wrapping {stash:embed name=“views/highlights/cards”} in index.html
* use the escaping method you hinted at
|
|
|
Mark Croxton
|
Posted: 11 February 2014 05:47 AM |
# 13
|
|
Developer
|
Great! Glad you got it working.
|
|
|
Fusionary
|
Posted: 11 February 2014 10:52 AM |
# 14
|
|
|
One drawback to full page caching in this way I’m noticing is any templates that _don’t_ have a stash:cache tag, now don’t properly render the embed because it has the nocache tag in it.
Is there any way around that, other than just including a cache tag on every page that includes that embed down the line?
|
|
|
Fusionary
|
Posted: 11 February 2014 12:59 PM |
# 15
|
|
|
I guess for those templates I don’t want to wrap in a cache tag, but still have that embed, I can just use parse_stage=“both” on the embed.
|
|
|