RE: Liferay DXP 7.0 Caching Web Content Structure/Templates

John Cressman, modified 6 Years ago. Junior Member Posts: 39 Join Date: 8/15/17 Recent Posts
I have created a web content structure with 4 fields: role, button name, button image, and url - and a seperator.  I then created a template for the structure that iterates through the entries and draws buttons (clickable divs) based on whether you have the correct role for the button.

This actually works.  For instance, my user account has 2 of the roles and I see two buttons.  BUT, when I impersonate a user that has 3 roles, I still see 2 roles.  Sounds like an issue with impersonate, but it's not.

If I log out, then go to a different page and impersonate the user with 3 roles and THEN go to the template, I see 3 buttons.  If It stop impersonating, I STILL see 3 buttons even though I only have access to 2.

So that seems to be a caching issue.  I've turned off Freemarker caching (Configuration -> System Setings -> Foundation -> Freemarker Engine), but that seems to make no difference whatsoever.

​​​​​​​Anyone else know why Liferay is acting this way?  Is there a way to prevent it from doing this?
thumbnail
Olaf Kock, modified 6 Years ago. Liferay Legend Posts: 6441 Join Date: 9/23/08 Recent Posts
John CressmanI have created a web content structure with 4 fields: role, button name, button image, and url - and a seperator.  I then created a template for the structure that iterates through the entries and draws buttons (clickable divs) based on whether you have the correct role for the button.

This actually works.  For instance, my user account has 2 of the roles and I see two buttons.  BUT, when I impersonate a user that has 3 roles, I still see 2 roles.  Sounds like an issue with impersonate, but it's not.

If I log out, then go to a different page and impersonate the user with 3 roles and THEN go to the template, I see 3 buttons.  If It stop impersonating, I STILL see 3 buttons even though I only have access to 2.

So that seems to be a caching issue.  I've turned off Freemarker caching (Configuration -> System Setings -> Foundation -> Freemarker Engine), but that seems to make no difference whatsoever.

​​​​​​​Anyone else know why Liferay is acting this way?  Is there a way to prevent it from doing this?

As template processing can involve service calls, it can be really costly. For this reason, each template itself has a "cacheable" checkbox. Go to the template editor and find that checkbox. Uncheck it. Done.

I'd expect the Freemarker Engine caching rather to affect the new parsing of the template rather than the new execution of the template - e.g. I'd recommend to leave it switched on. However, this (second statement) is only my expectation, not my knowledge or experience. Take it with a grain of salt.
John Cressman, modified 6 Years ago. Junior Member Posts: 39 Join Date: 8/15/17 Recent Posts
Olaf Kock
John CressmanI have created a web content structure with 4 fields: role, button name, button image, and url - and a seperator.  I then created a template for the structure that iterates through the entries and draws buttons (clickable divs) based on whether you have the correct role for the button.

This actually works.  For instance, my user account has 2 of the roles and I see two buttons.  BUT, when I impersonate a user that has 3 roles, I still see 2 roles.  Sounds like an issue with impersonate, but it's not.

If I log out, then go to a different page and impersonate the user with 3 roles and THEN go to the template, I see 3 buttons.  If It stop impersonating, I STILL see 3 buttons even though I only have access to 2.

So that seems to be a caching issue.  I've turned off Freemarker caching (Configuration -> System Setings -> Foundation -> Freemarker Engine), but that seems to make no difference whatsoever.

​​​​​​​Anyone else know why Liferay is acting this way?  Is there a way to prevent it from doing this?

As template processing can involve service calls, it can be really costly. For this reason, each template itself has a "cacheable" checkbox. Go to the template editor and find that checkbox. Uncheck it. Done.

I'd expect the Freemarker Engine caching rather to affect the new parsing of the template rather than the new execution of the template - e.g. I'd recommend to leave it switched on. However, this (second statement) is only my expectation, not my knowledge or experience. Take it with a grain of salt.

Thank you very much!  That was it!  A word to anyone else who does this - after you make the change to the template, even the cacheable change, you have to go back to the web content and repubublish it for it to take effect.