I am working on a Magento 2.4.1 extension that has some special requests where I need your advice on how to handle some technical aspects in a better way.
Basically, when a user logs in or a visitor visits the store for the first time, I need to set up some session parameters that will be injected into the product page. These variables come from the admin area and are updated every hour (into the session). For example, if I just accessed the store, I got my variables in the customer session. If the admin does some changes in the backend area around the same time, it will update my variables into the session in ~1 hour.
The problem I am facing is related to FPC because if I try to print the session on the product page, it won't show those variables. However, if I will print the session in a different controller, it will show those variables. I read some topics and articles that mentioned this particular situation is strongly connected to FPC and Private Content, but I would love to see your thoughts on this situation and on my two following questions:
- Following my description, do you think it's a good idea for me to keep storing those variables in the customer's session for both logged-in customers and visitors or do you have a better idea (ex. using cookies)? Please consider also that some variables are strongly related to different customer-related variables such as customer group, country, store view, etc.
- If it will be to continue using the customer's session, how can I treat these special customer session variables as private/non-cacheable so that I can access them when I want without having them removed from the session due to FPC/Private Content, even if the product page is cached?
Looking forward to hearing back from you.
Thanks!