-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
Disable caching for block doesn't work #1817
Comments
Step one for me is to make sure the module has been recognized and loaded. If you go in the Admin interface, Stores > Configuration > Advanced > Advanced > "Disable Modules Output" there is a list of all the modules that are loaded. Step 1 is to make sure your module is being loaded. I am guessing you got past this stage however and have some output up. (Just checking!!) If you delete var/*, wipe all the caches, restart the web server, etc - can you get the echo 'test' to come up? I just wanted to confirm that you are sure your module is being called (all the layout files injecting your module are working - it is just a caching issue). I wanted to confirm this as step 1, before looking into whether there is a problem with the caching flag. I was not sure how much you knew was working vs not working yet. Are you sure it is calling your block at all? (Then we can focus on the caching side.) |
The module is loaded for sure. The first time we load a product, our own stock is shown, for example "In Stock" (we call a rest service). The second time, it's always the same. No matter what we change to our stock in the backend. Also when I add echo 'test'; when the page was already loaded it's not shown. When it's the first time it works fine. So my module is working. When I remove all caches manually or through backend (full page cache), it's working again. |
@alankent what do you think? |
Sounds like a potential block caching bug. At that level I will leave to the engineering team to look into - I don't know the details of that code. Note: Is there a reason you have not used the Magento 2 REST API support rather than using a PHTML file? That is the direction we are moving towards. Then you get all the API authentication options etc. E.g. http://devdocs.magento.com/guides/v2.0/get-started/bk-get-started-api.html |
Note that you need to be a bit careful with PHTML files for a REST API. The cacheable flag is designed to work with a HTML page where parts of that page should not be cached. We use JavaScript to asynchronously populate the "non-cacheable" parts of a page (with static caching of the rest of the page). So there might be something funny going on here with that behavior if it is not for a web browser displaying a page. The web service API support is how we recommend API calls come in. |
We're not using the stock management of Magento, but a 3rd party rest service which returns the stock. So based on the response, we display another value on the webpage. <?php
$_stock = -1; //$block->getStock();
?>
<div class="xxx-stock">
<?php
if($_stock > 0) {
?><p class="available"><?php echo __('InStock'); ?></p><?php
} else if(is_null($_stock)) {
?><p class="error"><?php echo __('NotAvailable'); ?></p><?php
} else if($_stock <= 0) {
?><p class="unavailable"><?php echo __('OutOfStock'); ?></p><?php
} else {
?><p class="error"><?php echo __('NotAvailable'); ?></p><?php
}
?>
</div> So, it indeed is a webpage, which should call the 3rd party rest service every time the page is displayed, no caching.. |
Ah! Thanks. Got it. I will make sure the relevant core engineering team relevant to this area look at this request. |
Any news on this one? |
@rklerck I apologize for the delay. We monitor github regularly and usually respond faster. There is internal issue MAGETWO-45402 and we are working on it. Adding cacheable="false" to block declaration supposed to make page that contains this block uncacheable. Having this block on product page will hurt performance. The better way, as @alankent mentioned, would be to load this block via AJAX. I'm working to provide you practical advices. |
Hey, any news how to disable block from caching? |
Also looking for any updates to this behavior, as we are experiencing similar. |
same here |
@rklerck @cgrechcw @po2go-sean @sunilit42 It looks like this issue is fixed on the latest develop branch. Please make sure refresh layouts cache type after you update any layout. The cached layout without your change can be still used, which may appear that this function is not working correctly. |
@ALL closing due to non-responsiveness. |
Hello, If it is fixed, then provide us one example how to prevent block from caching on product view page? |
Yes - I'd like to do that too. |
Why there is no updates on this important issue? I am also looking for the same. |
Any update on this ? Coz this is something really critical when u have user based pricing in a B2B scenario. |
I am also facing this issues , |
[EngCom] Public Pull Requests - 2.1-develop - MAGETWO-85180: [Backport 2.1-develop] Fix swagger-ui on instances of Magento running on a non-standard port #12579 - MAGETWO-85097: [Backport-2.1] Added namespace to product videos fotorama events #12558 - MAGETWO-83478: Add command to view mview state and queue #12050
We developed an extension which returns the stock level from our backoffice. The extension contains a block with template (class + phtml). Inside the phtml the request is done to the class to get the stock. This shouldn't be cached, so I set the "cacheable" of the block to "false". But even when I add something directly in the phtml (like echo 'test';), it isn't displayed!
What am I doing wrong here, or is the caching mechanism not properly turned off?
The text was updated successfully, but these errors were encountered: