Power Pages – how not to cache signed in user data

By | September 16, 2025

I know you won’t like it. I don’t like it myself. And, yet, Power Pages caching has a tendency to be a pain in the neck every now and then.

For example, in my case, we store the # of notifications on the contact record (which maps to the “user” object in Liquid). That number gets updated periodically, and it has to show up in the user interface properly as soon as it’s been updated, since such updates happen in response to the user actions.

If it were the only such field, perhaps I’d do it differently, but there are at least two more.

So… what can one do about it? Well, perhaps bypassing the cache is not going to be such a bad idea. Although, perhaps you’d still say it’s a terrible idea, but there is one important benefit – it makes things simple, and it works. Here is the code sample, notice how, in the end, there is an assign statement that replaces default “user” object with the one loaded dynamically (also notice how dateFilterValue is being used in the FetchXml condition to essentially disable caching):

{% if now | date: 'HH:mm:ss' > '12:00:00' %}
  {% assign dateFilterValue = now | date: 'yyyy-MM-dd hh:mm:ss' | append: ' PM'%}
{% else %}
  {% assign dateFilterValue = now | date: 'yyyy-MM-dd hh:mm:ss' | append: ' AM'%} 
{% endif %}

{% capture contactQuery %}
            <fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true" no-lock="false">
                    <entity name="contact">
                    <all-attributes></all-attributes>
                    <filter type="and">
                        <condition attribute="createdon" operator="lt" value="{{dateFilterValue}}"></condition>
                        <condition attribute="contactid"  operator="eq" value="{{user.Id}}"></condition>
                    </filter>
                </entity>
            </fetch>
{% endcapture %}


{% fetchxml contactQueryResult %}
{{ contactQuery }}
{% endfetchxml %}

{% if contactQueryResult.results.entities.size > 0 %}
{% assign user = contactQueryResult.results.entities[0] %}
{% endif %}

PS. I'm re-setting default "user" variable above, and that may have some non-intended consequences, at least in theory. If you wanted to avoid doing that, you could just add your own variable somewhere in the header of the site, assign a value to it using the query above, and use it throughout the site whenever you needed "up to date" data.

Leave a Reply

Your email address will not be published. Required fields are marked *