0

I have a site with a large megamenu which is made up of the following types of code:

Setting category lists

{exp:stash:set_list
    name="product_categories"
    parse_tags="yes"
    save="yes"
    scope="site"
    refresh="1440"
    replace="no"
}
    {exp:gwcode_categories
        group_id="1|3|4|5|6"
        excl_cat_id="35|36|51|56|60|23|27|46|47|63|40|42|44|45|53|59|62|66|69"
        depth="1|2"
        parse="inward"
        style="linear"
    }
        {stash:cat_id}{cat_id}{/stash:cat_id}
        {stash:cat_depth}{depth}{/stash:cat_depth}
        {stash:parent_id}{parent_id}{/stash:parent_id}
        {stash:group_id}{cat_group_id}{/stash:group_id}
        {stash:cat_name}{cat_name}{/stash:cat_name}
        {stash:cat_url_title}{cat_url_title}{/stash:cat_url_title}
        {stash:complete_path}{complete_path}{/stash:complete_path}
        {stash:cat_image}{cat_image}{/stash:cat_image}
    {/exp:gwcode_categories}
{/exp:stash:set_list}

Getting the lists

{exp:query sql="SELECT COUNT(entry_id) num_cat_entries
    FROM
    (
            SELECT  entry_id
            FROM    exp_category_posts
            WHERE   cat_id IN (31, 73)
            GROUP   BY entry_id
            HAVING  COUNT(DISTINCT cat_id ) = 2
    ) s"
}
<div class="col_4">
    <h3>{stash:_cat_hd}</h3>
    <ul class="nb">
    {if '{stash:_group_id}'!=''}
        {exp:stash:get_list
            name="product_categories"
            match="#^{stash:_group_id}#"
            against="group_id"
        }
        {if '{stash:_group_id}'!='5' OR ('{stash:_group_id}'=='5' AND num_cat_entries > 0)}<li>
            <a href="{path={stash:_parent_url}/{cat_url_title}}/" data-cat-id="cat_{cat_id}" data-cat-img="{if cat_image}{exp:ce_img:single src='{cat_image}' width='240' crop='yes' bg_color='#444' url_only='yes'}{if:else}/assets/img/nav_product_generic.png{/if}">{cat_name}</a>
        </li>
        {/if}
        {/exp:stash:get_list}
    {/if}
    {if '{stash:_parent_id}'!=''}
        {exp:stash:get_list
            name="product_categories"
            match="#^{stash:_parent_id}#"
            against="parent_id"
        }
        <li>
            <a href="{path={stash:_parent_url}/{cat_url_title}}/" data-cat-id="cat_{cat_id}" data-cat-img="{if cat_image}{exp:ce_img:single src='{cat_image}' width='240' crop='yes' bg_color='#444' url_only='yes'}{if:else}/assets/img/nav_product_generic.png{/if}">{cat_name}
            </a>
        </li>
        {/exp:stash:get_list}
    {/if}
    </ul>
</div>
{/exp:query}

Then embedded them in the main globally embedded template

{stash:embed
    name="partials:nav_cat_get_list"
    stash:_group_id="4"
    stash:_parent_id=""
    stash:_parent_url="enclosures"
    stash:_cat_hd="Materials"
}

The menu also includes some Structure nav tags:

{exp:structure:nav
    include_ul="no"
    start_from="/markets/energy-resources"
    max_depth="1"
}

and a Super Search form:

    <form action="/results/" method="post">
    {exp:super_search:search}
    <label for="keywords">Search</label>
    <input type="search" id="keywords" name="keywords">
    <button type="submit">Go</button>
    {/exp:super_search:search}
</form>

Initially the processing of the nav was causing long delays for page loading so I wrapped the whole thing in:

{exp:stash:cache
  bundle="global"
  refresh="1440"
  replace="no"
}

with {stash:nocache} around the search form. That sorted out the page loading times but also killed off the form and replaced it with a string that started off with [_Stash_1_

I tried moving the form outside the stash:cache tag but then ended up with pages showing both the form and the odd [_Stash_1_ string.

So where am I going wrong, what do I need to do to cache the menu properly while also keeping the search form working?

2
  • Have you tried changing the parse_stage of the nav_cat_get_list embed to 'both' instead of using stash:cache (keeping nocache wrap for the form)? Oct 1 '14 at 17:49
  • Sorry, not sure I follow. Would you mind expanding in an answer?
    – Tyssen
    Oct 1 '14 at 21:17
1

As I mentioned on Twitter you should not need the Solpace tags to render your search form, according to the docs. The fact that your form does not work without them might point to another issue which you should explore with Solspace.

Nevertheless, if you want to investigate the cache escaping, please make sure you are using the latest version of Stash and create the following templates to create a reduced test of the problem.

  1. Create an EE template at templates/default_templates/tests/top.html with the following code:

    {exp:stash:cache}
      {stash:embed name="tests/middle"}
    {/exp:stash:cache}
    
  2. Create a Stash template at stash_templates/tests/middle.html with the following code:

    {stash:embed name="tests/bottom"}
    
  3. Create another Stash template at stash_templates/tests/bottom.html with the following code:

    <form action="/results/" method="post">
    {stash:nocache}
     {exp:super_search:search}
        <label for="keywords">Search</label>
        <input type="search" id="keywords" name="keywords">
        <button type="submit">Go</button>
      {/exp:super_search:search}
    {/stash:nocache}
    </form>
    

If you now view tests/top in your browser 3 variables should have been created in the exp_stash table, which you can verify with Mustash:

  1. tests/middle with the value:

    {stash:embed name="tests/bottom"}
    
  2. tests/bottom with the value:

    <form action="/results/" method="post">
    {stash:nocache}
     {exp:super_search:search}
        <label for="keywords">Search</label>
        <input type="search" id="keywords" name="keywords">
        <button type="submit">Go</button>
      {/exp:super_search:search}
    {/stash:nocache}
    </form>
    
  3. tests/top:cache with the value:

    <form action="/results/" method="post">
     {exp:super_search:search}
        <label for="keywords">Search</label>
        <input type="search" id="keywords" name="keywords">
        <button type="submit">Go</button>
      {/exp:super_search:search}
    </form>
    

tests/top:cache is the compiled cache of all the templates, and when you view tests/top a second time that variable alone with be retrieved and parsed.

Let me know if you get the output expected.

3
  • Following on from what I said on Twitter, it seems I can omit the super_search:search tags and the form still works fine which eliminates the original problem I was having (although having run through the test you outlined above, I got output as as expected). What I am having trouble with now is that when visiting new pages it seems like all the processing to create the nav is still being done on each page and it's not actually being pulled from cache, as first page load is slow, but subsequent loads are much faster.
    – Tyssen
    Oct 7 '14 at 1:59
  • I'm also having trouble with global nav variables not being cleared properly. I haven't installed Mustash yet, can I fix the issue by just clearing the contents of the exp_stash table?
    – Tyssen
    Oct 7 '14 at 2:06
  • Actually it seems like full pages are being cached because turning cacheing off for the global nav should result in slower loading times and an updated nav (new categories have been added), but I'm not seeing either. And I'm not explicitly using cacheing anywhere else except for the nav.
    – Tyssen
    Oct 7 '14 at 2:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.