Clear Cache in a macro

m weltin asked on December 9, 2021 19:47

Working in kentico 11. In my system users have an "EmployerName" property. When a user logs in, if they belong to a specific employer I want to alter them to update their profile to use a valid employer.

I have been able to get the behavior I'm looking for by using a macro inside the HTML envelope -> Content before of a Static HTML WebPart. See below for macro body.

I'm running into a UX issue where the CurrneUser.EmployerName is cached when the fist login. This causes my alter box to show even after they have made the necessary updates. I have tried using the Cache function and setting the time to 0, but that function evaluates the object, which I don't need.

How do I properly clear a cached object within a macro?

{% if(CurrentUser.EmployerName == "bad employer 1" || CurrentUser.EmployerName == "bad employer 2" || CurrentUser.EmployerName == "bad employer 3"){ %}
<div class="update-employer-name">
"Please update your <a href="/account">profile</a> to include a valid employer."
</div>
{% } #%}

Recent Answers


David te Kloese answered on December 9, 2021 22:17

Not sure why it would cache this value, as usually the user-like info is complete gone when you log out.

I'd verify the cache settings on all elements, template, page, Web Part both - 1. Performance > Partial cache minutes - 2. System settings > Cache minutes), Site Settings.

You could have a look at the Caching debugging (Settings > System > Debug > Cache access).


Alternatively it might be a good idea to move this whole logic to a custom macro. Might be a bit more work to setup, but gives a lot more flexibility and control. As well as making it easier to reuse on other places.

docs.xperience.io/k11/.../registering-custom-macro-methods

0 votesVote for this answer Mark as a Correct answer

m weltin answered on December 9, 2021 22:29

David: Thank you for your response. I did recently attempt to set the 'Partial cache minutes' for the web part to 0, however, that still did not give me the desired effect.

I'll try a custom macro as you suggested.

0 votesVote for this answer Mark as a Correct answer

Juraj Ondrus answered on December 10, 2021 12:40

What caching are you using? If you are caching the full page - output caching, then partial cache on web part level will not help. You need to disable full page cache for given page and then just use caching on the web part level. Or, when using full page cache, you could try using cache substitutions

1 votesVote for this answer Mark as a Correct answer

m weltin answered on December 10, 2021 16:24

Juraj: Thank you for pointing out that web part level caching is overridden by the full page caching strategy. I should have realized that this applies in my case. Unfortunately for me, this particular web part resides on the master page template and the majority of the child pages inherit the caching strategy. Turning off full page caching at that level may degrade site perform significantly.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.