Extension, Module

Archived
Forum
(read-only)

CE Cache

ExpressionEngine 2, ExpressionEngine 3

Back to this add-on's main page
View Other Add-ons From Causing Effect

1 of 2
1
   

CE Cache + Template Layouts

General (Resolved)

Sneed's Feed & Seed
Sneed's Feed & Seed

Hi Aaron,

I’m trying to figure out how to use CE Cache with EE’s new native template layouts. Here’s an example of my template setup:

test/layout:

<!DOCTYPE html>
<
html lang="en">
<
head>
 <
meta charset="UTF-8">
 <
title>Let's Make Biscuits!</title>
</head>
<body style="background-color: papayawhip;">
 {layout:contents}
</body>
</html> 

test/index

{layout='test/layout'}

<h1>No seriouslyLET'S MAKE SOME DAMN BISCUITS.</h1> 

So first I tried wrapping the layout in {exp:ce_cache:it} tags:

{exp:ce_cache:it}
<!DOCTYPE html>
<
html lang="en">
<
head>
 <
meta charset="UTF-8">
 <
title>Let's Make Biscuits!</title>
</head>
<body style="background-color: papayawhip;">
 {layout:contents}
</body>
</html>
{/exp:ce_cache:it} 

But that only cached the layout wrapper elements. Then I tried wrapping the contents data it its own cache tag:

{layout='test/layout'}

{exp
:ce_cache:it:contents}
 
<h1>No seriouslyLET'S MAKE SOME DAMN BISCUITS.</h1>
{/exp:ce_cache:it:contents} 

But that had the opposite effect, caching the contents and not the layout.

Last I tried wrapping the layout:contents tag in cache tags:

{exp:ce_cache:it}
<!DOCTYPE html>
<
html lang="en">
<
head>
 <
meta charset="UTF-8">
 <
title>Let's Make Biscuits!</title>
</head>
<body style="background-color: papayawhip;">
 {exp:ce_cache:it:contents}
  {layout:contents}
 {/exp:ce_cache:it:contents}
</body>
</html>
{/exp:ce_cache:it} 

But that just cached the layout again. I can’t wrap cache tags around the content template:

{exp:ce_cache:it}
 {layout
='test/layout'}

 
<h1>No seriouslyLET'S MAKE SOME DAMN BISCUITS.</h1>
{/exp:ce_cache:it} 

because the layout tag needs to be the first tag that’s parsed.

So I’m stumped. How do I do this?

 

Causing Effect - Aaron Waldon
# 1
Developer
Causing Effect - Aaron Waldon

Hi Kristen!

I really like your example template content and color choices. Unfortunately, CE Cache and native template layouts really don’t play well together, and there is not much I can do about it. The native template layouts don’t allow any other add-on tags to come before the {layout= } tag, so there is no hope in wrapping the entire template for efficient caching.

I wracked my brains on trying to get the two to play well together, and then abandoned the cause because the technical hurdles seemed insurmountably. There was a support thread on this topic a few months ago, but this is the first time anyone has asked about it since then.

Sneed's Feed & Seed
# 2
Sneed's Feed & Seed

Well damn, that really sucks. Guess I’ll have to use native caching.

Causing Effect - Aaron Waldon
# 3
Developer
Causing Effect - Aaron Waldon

Yeah, the situation does suck. You can also ask for a refund from the site of purchase (whether that be here on Devot:ee or on Causing Effect) within 30 days of purchase, if needed.

Jon Thomas
# 4
Jon Thomas

NOOOOOOOO! :)

I just ran into this and found this thread. Have to convert to stash layouts?

EllisLab
# 5
EllisLab

Aaron, last we heard from you in June, you indicated that you didn’t think it was limited by the layout tag positioning restriction, but due to layout tags being parsed before {exp: tags. and then we never heard back. Does CE Cache have the same problem with other things parsed prior to tags? Snippets, etc.?

Essentially, what is CE Cache needing ExpressionEngine to allow it to do that it currently doesn’t?

Andy Kelly
# 6
Andy Kelly

I hope the fact that this thread is marked RESOLVED is an error.

The CE Cache addon is the only thing that has enabled my site to
deliver a million pages in less than 24 hours and I need it desperately.
Please don’t let this addon go dormant.

Andy

EllisLab
# 7
EllisLab

Hopefully it’s not in error, maybe Aaron has solved it. We still haven’t heard from him, FWIW.

Causing Effect - Aaron Waldon
# 8
Developer
Causing Effect - Aaron Waldon

@Andy Kelly: Hi Andy, I’m happy to hear that CE Cache has helped you. CE Cache still works great, and it has not been abandoned. It just doesn’t work with the native template layouts at this point. There are several other ways to use template layouts though. I’m happy to see that EL is anxious to get CE Cache and native layouts to play well together. This thread was marked as Resolved (eg: answered), before the last few people chimed in.

@EllisLab (I presume this is Derek Jones I’m talking to?) Thanks for following up with this! I already explained a bit of the problem in our email thread when I contacted you guys about this issue, but I didn’t answer your follow-up email question about whether or not CE Cache can parse snippets.

I’ve been waiting for some time to run a ton of tests, figure out which changes need to be made to core, and send over a pull request, but I apparently live from one deadline to the next and haven’t gotten around to tackle this subject. I’m just going to post my understanding of the problem in this thread.

Does CE Cache have the same problem with other things parsed prior to tags? Snippets, etc.?

Not particularly, because the CE Cache tags can still wrap all of the content between them. CE Cache does some wizardry with the read-only template_fetch_template hook in order to “pre-escape” some global variables, but for the most part, CE Cache is just grabbing the tagdata that is being passed in.

Using CE Cache around the entire template for a layout page wouldn’t work (even if exp tags could show up before a {layout=...} tag), because the {layout=...} and {layout:set} tags have already been processed by the time the CE Cache tag runs. The template class is on it’s way to parsing content and piping it to the next template.

I think the root of the problem is what I said in a previous email: that the layouts are parsed before exp tags, so there is not really a way for CE Cache to get in there before they’re processed. Most every tag in EE is processed by the parser when it is reached, which has traditionally allowed CE Cache to work. However, the layouts tag seems to be parsed beforehand. When I was testing this a few months ago, there wasn’t even a way to see which layout was being used with the template_fetch_template hook when dumping the EE super object; the layouts tag was already stripped out.

In order for the two add-ons to play well, CE Cache would need to be able to have an entry point to the content before the parser was already doing the heavy lifting. It would need to be able to intercept the template content (and/or parts of it) before it’s processed, and decide whether or not to serve up previously cached content, or to process the template content and then cache it. That’s how everything worked for a long time.

Does that make sense?

EllisLab
# 9
EllisLab

That’s helpful Aaron, thanks. Do you mind re-posting this over in the Developer Preview private forums so our engineers can work this out with you?

Causing Effect - Aaron Waldon
# 10
Developer
Causing Effect - Aaron Waldon

Thanks EllisLab. Done!

Dovla
# 11
Dovla

has there been any update with regards to this problem? I’m working on a site and can’t use CE cache because of this. I really need the new template layouts feature. Stash is too much of a bother for me and with the new layout set options I don’t plan on using it anytime soon. I would love to use CE cache again as it has made my life a whole lot easier in the past.

Kelly Sims
# 12
Kelly Sims

We use template layouts and don’t have any problems with CE Cache. Although we do things slightly different than Kristen posted above.

We wrap the entire layout template with

{exp:ce_cache:it id="global-layout" global="yes"

Then wrap the layout contents like:

{exp:ce_cache:escape}{layout:contents}{/exp:ce_cache:escape} 

Then inside the template,

{layout="_layouts/site"}
{exp
:ce_cache:it id="homepage" global="no"}
blah blah blah
{
/exp:ce_cache:it} 

We do end up with two cached files instead of one, but we’ve never sen any speed degradation issues because of it.

Dovla
# 13
Dovla

Thank you so much for this! I have almost given up on CE Cache but it works great with your code. I’ll be implementing this into future projects for sure.

Cheers!

Causing Effect - Aaron Waldon
# 14
Developer
Causing Effect - Aaron Waldon

Hi Guys,

EllisLab asked that I send them a copy of CE Cache, but ultimately said that they did not want to add a hook that would allow the two to play well together. The hook would have needed to be added very early in the parse process, and I think they felt that they were opening up too many opportunities for people to extend or override the EE core functionality.

The post by Kelly looks promising. I continue to use other options, like CE Variables or Stash, as they provide the same functionality as template layouts, and are superior in many ways (IMHO). ;)

Newism
# 15
Newism

Nice work Kelly. I’ll be trying this out in our next build.

1 of 2
1