0

I have a module with a custom entity (product reviews) that is responsible for adding reviews to the product and rendering them on the product page in an additional tab. Service contract is present.

The issue is that I can't see the newly submitted review unless I flush the cache.

Is there any way to resolve it?

asked Jul 8 at 11:43
4
  • Check if Full Page cache is enabled or not ? Commented Jul 8 at 19:35
  • It is enabled and should stay that way. Is there a solution that invalidates the cache only for the certain product and review block? Commented Jul 8 at 20:48
  • 1
    It can be possible by using private content . Ref https://developer.adobe.com/commerce/php/development/cache/page/private-content. Commented Jul 9 at 5:45
  • Reviews are product-based and not customer-related. Ajax loading for the review list and pagination is rather hard to implement. Commented Jul 10 at 17:40

1 Answer 1

0

As mentioned in the question you have a module custom built which manages the product reviews.

If the module doesn't load the reviews unless you refresh the cache, then it's clear the module doesn't work with FPC enabled.

To make the module compatible with FPC you need to do the following

  1. The Model and Block class of the module which should have implemented Magento\Framework\DataObject\IdentityInterface.

  2. The model should have a CACHE_TAG property with your custom_cache_tag to identify like custom_product_review and method getIdentities which returns the cache tags with product and custom_review_id

     //Sample Code in your Model 
     /**
     * Cache tag value
     */
     public const CACHE_TAG = 'custom_product_review'; 
     /**
     * Return unique ID(s) for each object in system
     *
     * @return array
     */
     public function getIdentities()
     {
     $tags = [];
     if ($this->getEntityPkValue()) {
     $tags[] = \Magento\Catalog\Model\Product::CACHE_TAG . '_' . $this->getEntityPkValue();
     }
     return $tags;
     }
    
  3. The block should have a method getIdentities which returns the array of your custom_cache_tag.

//Sample Code in your Block 
/**
 * Return unique ID(s) for each object in system
 *
 * @return array
*/
public function getIdentities()
{
 return [\Magento\Review\Model\Review::CACHE_TAG];
}

The Identities method will refresh the FPC cache entry for the product review every time when it gets saved / removed.

answered Jul 9 at 14:01

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.