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?
1 Answer 1
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
The
ModelandBlockclass of the module which should have implementedMagento\Framework\DataObject\IdentityInterface.The model should have a
CACHE_TAGproperty with your custom_cache_tag to identify likecustom_product_reviewand methodgetIdentitieswhich 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; }The block should have a method
getIdentitieswhich 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.
Explore related questions
See similar questions with these tags.
private content. Ref https://developer.adobe.com/commerce/php/development/cache/page/private-content.