Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can a block be cached for period of time? #1591

Closed
Pakkapao opened this issue Jul 30, 2015 · 6 comments
Closed

Can a block be cached for period of time? #1591

Pakkapao opened this issue Jul 30, 2015 · 6 comments
Labels
Issue: Format is not valid Gate 1 Failed. Automatic verification of issue format is failed

Comments

@Pakkapao
Copy link

Hi,

Is it possible to cache a block for period of time, for example, it expires every 15 minutes? I would like to display a block on sidebar for all pages and to avoid performance issue as the information inside the block doesn't change frequently.

Is there an xml parameter available to do that?

<referenceContainer name="sidebar.additional">
    <block class="xxx" before="-" name="xxx" template="xxx.phtml" cacheable="true"/>
</referenceContainer>

Thanks,

@rganin
Copy link
Contributor

rganin commented Jul 30, 2015

Yes. A "ttl" attribute designed for setting cache lifetime for a block in seconds.

<referenceContainer name="sidebar.additional">
    <block class="xxx" before="-" name="xxx" template="xxx.phtml" cacheable="true" ttl="900"/>
</referenceContainer>

See sample in app/code/Magento/Doc/view/doc/layout/default.xml

@Pakkapao
Copy link
Author

Thank you for your help, rganin. 👍
I tried searching an example from code base before but didn't found any of them. I must have looked over them.

@Jakhotiya
Copy link
Contributor

You can find an example in file vendor/magento/module-theme/view/frontend/layout/default.xml

 <block class="Magento\Framework\View\Element\Template" name="store.menu" group="navigation-sections" template="Magento_Theme::html/container.phtml">
                    <arguments>
                        <argument name="title" translate="true" xsi:type="string">Menu</argument>
                    </arguments>
                    <block class="Magento\Theme\Block\Html\Topmenu" name="catalog.topnav" template="html/topmenu.phtml" ttl="3600" before="-"/>
                </block>

magento-team pushed a commit that referenced this issue Oct 16, 2017
@jarnail1004
Copy link

@rganin I try this "ttl" but it didnt work. I want to uncached BLOCK on product page and I try to use this TTL by setting to minimum time but its doent work. i am using maqgento 2.1.8

@magento-engcom-team magento-engcom-team added the Issue: Format is not valid Gate 1 Failed. Automatic verification of issue format is failed label Nov 14, 2017
@agoeurysky
Copy link

hi @jarnail1004 , I try this "ttl" attribute with a "60" value to have 1 minute for the cache lifetime, but it didn't work, like you. Do you have some information about it ?

@jarnail1004
Copy link

@agoeurysky , this works only if you are using Varnish cache.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue: Format is not valid Gate 1 Failed. Automatic verification of issue format is failed
Projects
None yet
Development

No branches or pull requests

6 participants