3

I'm still trying to fully wrap my brain around Stash's cacheing system.

From the docs it seems that both :set and :get have the parameters save, scope, replace, and refresh.

Is there a benefit to using both?

I had thought that perhaps saving on set could be used to store raw data and saving on get could be used to store formatted data. So for example:

{exp:stash:set_list name="products" parse_tags="yes" 
 save="yes" refresh="60" replace="no" scope="site"}
    {exp:low_variables:pair var="lv_products"}
        {stash:prod_image}{image}{/stash:prod_image}
        {stash:prod_url}{link}{/stash:prod_url}
        {stash:prod_title}{link_title}{/stash:prod_title}
    {/exp:low_variables:pair}
{/exp:stash:set_list}

And then:

{exp:stash:get_list:nested name="products"
 save="yes" refresh="60" replace="no" scope="site"}
{if count == 1}<ul>{/if}
    <li><a href="{other_prod_url}">{other_prod_image} <b>{other_prod_title}</b></a></li>
{/if count == total_results}</ul>{/if}
{/exp:stash:get_list:nested}

In a more "real world" example. I have a rather complex drop-down navigation that is built off nav:ee but includes low variables with playa, and matrix to create "mega-dropdowns" I stash each bit of data individually, but then also tried to stash the entire generated menu with the page uri as a context.

Is this a correct/beneficial "layered caching" approach? Or am I missing something here? :)

3

For the {exp:stash:get} tag save is only used with dynamic="yes" when retrieving dynamic values from $_POST, $_GET or segment arrays.

For your menu it only makes sense to stash the parts of your menu as separate lists if you are re-using those values elsewhere. Otherwise, just wrap the tags that generate the menu with a {exp:stash:set} with the output parameter set to yes so you don't need to get it:

{exp:stash:set name="main_menu" save="yes" scope="site" replace="no" output="yes" refresh="0"}
[various expensive tags that generate the menu]
{/exp:stash:set}

If this is a main menu then it would be wasteful to cache a unique instance for each page URI. If you need the menu markup to change to display an active state - based on the value of {segment_1} for example - then enclose the relevant conditionals with {stash:nocache} tag pairs to escape them from caching.

| improve this answer | |

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.