Cache breaks my check for detecting if a customer is logged inMagento 2: check customer logged in by javascript use modelCheck whether customer is loggedin in Magento 2 model classMagento2: How to update the product price programaticallycustomer session does not work except customer page - Magento 2Magento 2: get customer id of logged in user with cache enabledMagentoCustomerModelCustomer::__construct() must be an instance of MagentoFrameworkModelContextCustomer session for logged in customer by token based authenticationMagento get Customer Data from session idMagento 2.2.4 unable to get customer session dataMagento2 REST API get all customers detailsMagento 2.3 error after cache flush or clean

How do you say “buy” in the sense of “believe”?

Tic-tac-toe for the terminal, written in C

How strong are Wi-Fi signals?

Placing bypass capacitors after VCC reaches the IC

Full backup on database creation

How to capture more stars?

I unknowingly submitted plagiarised work

Is there a public standard for 8 and 10 character grid locators?

What is the most important source of natural gas? coal, oil or other?

Were pens caps holes designed to prevent death by suffocation if swallowed?

Is there a general effective method to solve Smullyan style Knights and Knaves problems? Is the truth table method the most appropriate one?

How does an ARM MCU run faster than the external crystal?

Integrating an absolute function using Mathematica

Can you heal a summoned creature?

Full horizontal justification in table

How did early x86 BIOS programmers manage to program full blown TUIs given very few bytes of ROM/EPROM?

Why does the 'metric Lagrangian' approach appear to fail in Newtonian mechanics?

Would jet fuel for an F-16 or F-35 be producible during WW2?

In general, would I need to season a meat when making a sauce?

When and what was the first 3D acceleration device ever released?

Employer asking for online access to bank account - Is this a scam?

Different circular sectors as new logo of the International System

Infinite Sequence based on Simple Rule

Crossing US border with music files I'm legally allowed to possess



Cache breaks my check for detecting if a customer is logged in


Magento 2: check customer logged in by javascript use modelCheck whether customer is loggedin in Magento 2 model classMagento2: How to update the product price programaticallycustomer session does not work except customer page - Magento 2Magento 2: get customer id of logged in user with cache enabledMagentoCustomerModelCustomer::__construct() must be an instance of MagentoFrameworkModelContextCustomer session for logged in customer by token based authenticationMagento get Customer Data from session idMagento 2.2.4 unable to get customer session dataMagento2 REST API get all customers detailsMagento 2.3 error after cache flush or clean






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















When I turned off cache (bin/magento cache:disable) the below code works otherwise it's not working.



$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$customerSession = $objectManager->get('MagentoCustomerModelSession');

if($customerSession->isLoggedIn())
echo "logged in";
else
echo "no logged";










share|improve this question
























  • bin/magento cache:disable if i go guest i got no logged if i go customer i got loged. bin/magento cache:enable if i go guest i got no loged if go customer ig ot no loged

    – Ibrahim Aldar
    May 21 at 13:23






  • 1





    The response is just getting cached. Itt will work on first load however remain the same for each request thereafter if that is what you are experiencing. There are Javascript alternatives for this that will work magento.stackexchange.com/questions/263905/…

    – harri
    May 21 at 13:33












  • You can NOT use the code like this. where you want to use check customer session?

    – Amit Bera
    May 21 at 13:39


















0















When I turned off cache (bin/magento cache:disable) the below code works otherwise it's not working.



$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$customerSession = $objectManager->get('MagentoCustomerModelSession');

if($customerSession->isLoggedIn())
echo "logged in";
else
echo "no logged";










share|improve this question
























  • bin/magento cache:disable if i go guest i got no logged if i go customer i got loged. bin/magento cache:enable if i go guest i got no loged if go customer ig ot no loged

    – Ibrahim Aldar
    May 21 at 13:23






  • 1





    The response is just getting cached. Itt will work on first load however remain the same for each request thereafter if that is what you are experiencing. There are Javascript alternatives for this that will work magento.stackexchange.com/questions/263905/…

    – harri
    May 21 at 13:33












  • You can NOT use the code like this. where you want to use check customer session?

    – Amit Bera
    May 21 at 13:39














0












0








0








When I turned off cache (bin/magento cache:disable) the below code works otherwise it's not working.



$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$customerSession = $objectManager->get('MagentoCustomerModelSession');

if($customerSession->isLoggedIn())
echo "logged in";
else
echo "no logged";










share|improve this question
















When I turned off cache (bin/magento cache:disable) the below code works otherwise it's not working.



$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$customerSession = $objectManager->get('MagentoCustomerModelSession');

if($customerSession->isLoggedIn())
echo "logged in";
else
echo "no logged";







magento2 customer cache






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited May 21 at 13:31









harri

3,13611661




3,13611661










asked May 21 at 13:22









Ibrahim AldarIbrahim Aldar

283




283












  • bin/magento cache:disable if i go guest i got no logged if i go customer i got loged. bin/magento cache:enable if i go guest i got no loged if go customer ig ot no loged

    – Ibrahim Aldar
    May 21 at 13:23






  • 1





    The response is just getting cached. Itt will work on first load however remain the same for each request thereafter if that is what you are experiencing. There are Javascript alternatives for this that will work magento.stackexchange.com/questions/263905/…

    – harri
    May 21 at 13:33












  • You can NOT use the code like this. where you want to use check customer session?

    – Amit Bera
    May 21 at 13:39


















  • bin/magento cache:disable if i go guest i got no logged if i go customer i got loged. bin/magento cache:enable if i go guest i got no loged if go customer ig ot no loged

    – Ibrahim Aldar
    May 21 at 13:23






  • 1





    The response is just getting cached. Itt will work on first load however remain the same for each request thereafter if that is what you are experiencing. There are Javascript alternatives for this that will work magento.stackexchange.com/questions/263905/…

    – harri
    May 21 at 13:33












  • You can NOT use the code like this. where you want to use check customer session?

    – Amit Bera
    May 21 at 13:39

















bin/magento cache:disable if i go guest i got no logged if i go customer i got loged. bin/magento cache:enable if i go guest i got no loged if go customer ig ot no loged

– Ibrahim Aldar
May 21 at 13:23





bin/magento cache:disable if i go guest i got no logged if i go customer i got loged. bin/magento cache:enable if i go guest i got no loged if go customer ig ot no loged

– Ibrahim Aldar
May 21 at 13:23




1




1





The response is just getting cached. Itt will work on first load however remain the same for each request thereafter if that is what you are experiencing. There are Javascript alternatives for this that will work magento.stackexchange.com/questions/263905/…

– harri
May 21 at 13:33






The response is just getting cached. Itt will work on first load however remain the same for each request thereafter if that is what you are experiencing. There are Javascript alternatives for this that will work magento.stackexchange.com/questions/263905/…

– harri
May 21 at 13:33














You can NOT use the code like this. where you want to use check customer session?

– Amit Bera
May 21 at 13:39






You can NOT use the code like this. where you want to use check customer session?

– Amit Bera
May 21 at 13:39











1 Answer
1






active

oldest

votes


















0














The block responsible for rendering the template which contains the logic above is cached.



Couple of options



To disable caching of custom block on a Magento 2 product view page, you can implement a couple of different approaches:



In a layout, set cacheable=”false”. Note that this attribute will make the whole page non-cacheable.



Alternatively, you can set _isScopePrivate property to true in a block class. By implementing this approach, you instruct a page cache module to replace your block content with placeholder before caching. When the page is loaded from cache, your block can be rendered via Ajax request. Check MagentoCaptchaBlockCaptcha::__construct and related layouts/templates as an example.






share|improve this answer























    Your Answer








    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "479"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f275487%2fcache-breaks-my-check-for-detecting-if-a-customer-is-logged-in%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    The block responsible for rendering the template which contains the logic above is cached.



    Couple of options



    To disable caching of custom block on a Magento 2 product view page, you can implement a couple of different approaches:



    In a layout, set cacheable=”false”. Note that this attribute will make the whole page non-cacheable.



    Alternatively, you can set _isScopePrivate property to true in a block class. By implementing this approach, you instruct a page cache module to replace your block content with placeholder before caching. When the page is loaded from cache, your block can be rendered via Ajax request. Check MagentoCaptchaBlockCaptcha::__construct and related layouts/templates as an example.






    share|improve this answer



























      0














      The block responsible for rendering the template which contains the logic above is cached.



      Couple of options



      To disable caching of custom block on a Magento 2 product view page, you can implement a couple of different approaches:



      In a layout, set cacheable=”false”. Note that this attribute will make the whole page non-cacheable.



      Alternatively, you can set _isScopePrivate property to true in a block class. By implementing this approach, you instruct a page cache module to replace your block content with placeholder before caching. When the page is loaded from cache, your block can be rendered via Ajax request. Check MagentoCaptchaBlockCaptcha::__construct and related layouts/templates as an example.






      share|improve this answer

























        0












        0








        0







        The block responsible for rendering the template which contains the logic above is cached.



        Couple of options



        To disable caching of custom block on a Magento 2 product view page, you can implement a couple of different approaches:



        In a layout, set cacheable=”false”. Note that this attribute will make the whole page non-cacheable.



        Alternatively, you can set _isScopePrivate property to true in a block class. By implementing this approach, you instruct a page cache module to replace your block content with placeholder before caching. When the page is loaded from cache, your block can be rendered via Ajax request. Check MagentoCaptchaBlockCaptcha::__construct and related layouts/templates as an example.






        share|improve this answer













        The block responsible for rendering the template which contains the logic above is cached.



        Couple of options



        To disable caching of custom block on a Magento 2 product view page, you can implement a couple of different approaches:



        In a layout, set cacheable=”false”. Note that this attribute will make the whole page non-cacheable.



        Alternatively, you can set _isScopePrivate property to true in a block class. By implementing this approach, you instruct a page cache module to replace your block content with placeholder before caching. When the page is loaded from cache, your block can be rendered via Ajax request. Check MagentoCaptchaBlockCaptcha::__construct and related layouts/templates as an example.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered May 21 at 21:41









        Dominic XigenDominic Xigen

        61511




        61511



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Magento Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f275487%2fcache-breaks-my-check-for-detecting-if-a-customer-is-logged-in%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

            Circuit construction for execution of conditional statements using least significant bitHow are two different registers being used as “control”?How exactly is the stated composite state of the two registers being produced using the $R_zz$ controlled rotations?Efficiently performing controlled rotations in HHLWould this quantum algorithm implementation work?How to prepare a superposed states of odd integers from $1$ to $sqrtN$?Why is this implementation of the order finding algorithm not working?Circuit construction for Hamiltonian simulationHow can I invert the least significant bit of a certain term of a superposed state?Implementing an oracleImplementing a controlled sum operation

            Magento 2 “No Payment Methods” in Admin New OrderHow to integrate Paypal Express Checkout with the Magento APIMagento 1.5 - Sales > Order > edit order and shipping methods disappearAuto Invoice Check/Money Order Payment methodAdd more simple payment methods?Shipping methods not showingWhat should I do to change payment methods if changing the configuration has no effects?1.9 - No Payment Methods showing upMy Payment Methods not Showing for downloadable/virtual product when checkout?Magento2 API to access internal payment methodHow to call an existing payment methods in the registration form?