Power pages use extensive caching to serve content faster and improve performance. However, this caching sometimes results in stale data being served. It is possible to prevent power pages from caching the fetchXML queries.
One way to avoid caching is to add a createdon
filter in the fetch XML as shown below –
<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
<entity name="invoices">
<attribute name="invoiceid" />
<attribute name="invoicenumber" />
<attribute name="createdon" />
<order attribute="invoicenumber" descending="false" />
<filter type="and">
<condition attribute="createdon" operator="on-or-before" value='{{ "today" | date: "yyyy-MM-dd HH:mm:ss" }}' />
</filter>
</entity>
</fetch>
Since the record’s createdon
value will always be less than the current date.
Since the current date and time will change for every request, power pages cannot cache your fetch XML query.
Since this approach solves the caching issue by querying the database for every request in power pages, it might impact your portal’s performance. So be mindful of the trade-off between data freshness and performance and use it only when necessary.