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

     

CE Cache issue with new layouts feature in 2.8.1

Support Request

Dan Kingsley
Dan Kingsley

Hi,

I’m not sure if this is a problem with my setup or the new feature in EE 2.8. However when I add caching tags to a layout template - something as simple as this:

{exp:ce_cache:it}
    {embed
="includes/.header_top"}
    {embed
="includes/.header_bottom"}
    {layout
:contents}
    {embed
="includes/.footer"}
{
/exp:ce_cache:it} 

It doesn’t seem to be working - the header and footer embeds work, however there is nothing output with the layout:contents tag. Removing the caching tags fixes the issue.

I have no problems with ce cache if I don’t use the layout template feature.

Thanks!

Philip
# 1
Philip

Following, because I’m having the same issue.

Philip
# 2
Philip

Hey Dan,

Did you ever find a resolution to this?

Dan Kingsley
# 3
Dan Kingsley

Hi,

Nope, still not a resolution and haven’t actually heard back at all! I imagine it’s a known bug and they are working on it… but maybe that’s too much of an assumption!

Dan

Brendan Underwood
# 4
Brendan Underwood

Having same problem here.

With CE Cache, this doesn’t work:

{layout="_layouts/base" title="The Title"}

{exp
:ce_cache:it id="page-home" tag="home" seconds="14400"}

{exp
:channel:entries channel="site_content" limit="1"}

    
<h1>{title}</h1>

    
{cf_content_body}

    {layout
:set name="page_title"}
        {title}
    {
/layout:set}
    {layout
:set name="page_description"}
        {cf_content_summary}
    {
/layout:set}

{
/exp:channel:entries}

{
/exp:ce_cache:it} 

Without CE Cache, it does work:

{layout="_layouts/base" title="The Title"}


{exp
:channel:entries channel="site_content" limit="1"}

    
<h1>{title}</h1>

    
{cf_content_body}

    {layout
:set name="page_title"}
        {title}
    {
/layout:set}
    {layout
:set name="page_description"}
        {cf_content_summary}
    {
/layout:set}

{
/exp:channel:entries} 

Not sure if I continue on with layouts now and hope that CE Cache sorts out any problems for later or not.

Causing Effect - Aaron Waldon
# 5
Developer
Causing Effect - Aaron Waldon

@Dan, Philip, and Brendan: I think I have a beta version of CE Cache that should play better with EE 2.8.x. Please email me at software at causingeffect.com if you would be willing to try it out.

@Brendan: Keep in mind that CE Cache caches the output from a part of a template. If the the layout tags are within the CE Cache tag, then once the page is cached, the Cache It tag will simply return what was output when it was first run (which is nothing).

For example, let’s say I have a page template, and a layout template:

Page Template:

{layout="layouts/_master" title="The Homepage"}

{layout
:set name="contents"}
 
<p>This is the page's content.</p>
{/layout:set} 

Layout Template:

<!DOCTYPE html>
<
html>
<
head>
 <
meta charset="utf-8">
 <
title>{layout:title}</title>
</
head>
<
body>
 
{layout:contents}
</body>
</
html

This part of the “page template” doesn’t actually output anything:

{layout:set name="contents"}
 
<p>This is the page's content.</p>
{/layout:set} 

So if we cached that chunk of code

{exp:ce_cache:it}
{layout
:set name="contents"}
 
<p>This is the page's content.</p>
{/layout:set}
{/exp:ce_cache:it} 

, the cached data would actually be an empty string (”“).

Once cached, the Cache It tag would literally replace this:

{exp:ce_cache:it}
{layout
:set name="contents"}
 
<p>This is the page's content.</p>
{/layout:set}
{/exp:ce_cache:it} 

with nothing (an empty string “”).

Which means that the layout variables would never be set.

Just be sure to always cache both the code that sets a variable *and* the code that gets the variable into the same cache item, or don’t cache either of them. If you cache one or the other, then nothing will ever be output. However, there is no problem with caching the code that goes inside of the setter:

{layout:set name="contents"}
{exp
:ce_cache:it id="contents"}
<p>This is the page's content.</p>
{/exp:ce_cache:it}
{/layout:set} 


I recommend using the same layout approach, but using CE Vars or Stash to set the variables and handle the layout instead. The fact that the {embed} for the template layout can be used inside of the CE Cache tags makes the page a lot more flexible and efficient, because the entire page can be cached while escaping pieces of the page from being cached (any embeds are completely flattened out once cached anyway). There is no way to wrap the entire “page template” tag with the Cache It tag, since the {layout=...} code always has to be on the very first line.

Brendan Underwood
# 6
Brendan Underwood

Thanks for that quick bit of info. I have been struggling with the decision of whether to use the new Template Layouts, or use existing methods of {embeds}. What you’ve mentioned makes sense. Just the bit about CE Vars and Stash needs to be learnt now. Any really good tutorials that explains how CE Vars and/or Stash should be implemented as a best practice?

Causing Effect - Aaron Waldon
# 7
Developer
Causing Effect - Aaron Waldon

@Brendan I just released a new version of CE Variables (there’s a template partials intro write-up here) and a new add-on called In. I have been using both to build websites for some time. CE Cache plays well with them too. I hope you find those resources useful. :)