cancel
Showing results for 
Search instead for 
Did you mean: 

Catalog New Products List Widget cache hole punching

SOLVED

Catalog New Products List Widget cache hole punching

I'm using Magento's Catalog New Products List widget on my homepage (inserted via the CMS editor Content > Pages) and I can't get it to refresh when products changes. I tried setting a cache_lifetime of 1 or 0 through the widget **bleep** and it does not seem to work. I then went and edited the widget itself at Model/Catalog/Block/Product/NewProduct.php to force it to have either a cache_lifetime of 1 or null and it does not refresh either when I add new products or change images / price / name.

 

I also went and made a plugin to modify the getCacheKeyInfo to see if it would make a difference but it does not.

 

I'm kinda lost at what to search for now. I don't see where I can make it so the widget's cache is cleared on product changes...

 

Edit: I went and made sure that cache was indeed disabled for the widget by adding this:

 

// This is a test.
    protected function getCacheLifetime(){
        error_log("Getting Cache Lifetime");
        return null;
    }

The function is called once when the page is loaded after a cache:flush but then it is never called again until another cache:flush.

 

1 ACCEPTED SOLUTION

Accepted Solutions

Re: Catalog New Products List Widget cache hole punching

Managed to get it working using identities related to each products like so:

 

/**
     * Return identifiers for produced content
     *
     * @return array
     */
    public function getIdentities()
    {   
        $identities = [];

        foreach ($this->_getProductCollection() as $item) {
            $identities = array_merge($identities, $item->getIdentities());
        }

        return $identities;
        
        //return [\Magento\Catalog\Model\Product::CACHE_TAG];
    }

As glad as I am that it finally works I don't understand why cache_lifetime did not work even though identities weren't set.

View solution in original post

1 REPLY 1

Re: Catalog New Products List Widget cache hole punching

Managed to get it working using identities related to each products like so:

 

/**
     * Return identifiers for produced content
     *
     * @return array
     */
    public function getIdentities()
    {   
        $identities = [];

        foreach ($this->_getProductCollection() as $item) {
            $identities = array_merge($identities, $item->getIdentities());
        }

        return $identities;
        
        //return [\Magento\Catalog\Model\Product::CACHE_TAG];
    }

As glad as I am that it finally works I don't understand why cache_lifetime did not work even though identities weren't set.