Archive

Archive for May 9, 2019

ADX Portals – Clear Cache On Web Page Submission

Adxstudio Portal application caches the results from Dynamics CRM to improve the performance.

But, there are times, where we need to override (invalidate) cache behavior to show latest data on Portals. Lets take a scenario

  • My Portal has a ‘Contact’ web page and up on ‘Submit’, a plug-in updates all the associated ‘Cases’ in the background.
  • Now, on Portal, navigate to ‘Cases’ entity list Web Page, which should show the latest ‘Cases’ data, which has been updated by plug-in in above step.

In above scenario, we will not get the latest ‘Cases’ due to Portal Cache behavior.

So what are the ‘Cache Invalidation’ options?

  • Manual Cache Invalidation:
    • This option is to manually hit the JavaScript bookmark-let  as specified here.
    • Drawback:
      • Its not viable, to ask portal users to hit the URL every time they ‘Submit’ the ‘Contact’ web page
  • Web Notifications:
    • A Web Notification Plugin registered with the Adxstudio Portals solution in CRM is triggered on all entity create, update, delete, disassociate, associate, publish, and publish all messages and notifies the Web Notification URLs defined in the CRM to invalidate the cache so the users visiting the portal get the recent data changes
    • Drawback:
      • A ‘System Job’ gets created up on update of the entity, and the execution may get delayed based on the occupancy of CRM Async Service Job.
      • This is not fool proof solution.

ADX Cache_1

We took an approach to automate the ‘Manual Cache Invalidation’ process to fetch the latest CRM data.

Our Cache Invalidation Approach :

  • Create a new ‘Web Page’ and paste below ‘Manual Cache Invalidation JavaScript’ code in ‘Custom JavaScript’ field.
    • Note: You don’t need to associate any ‘Web Form’, ‘Entity List’ or ‘Entity Form’ to this Web Page.

$(document).ready(function () {
var url = document.location.protocol + ‘//’ + document.location.host + (document.location.host.indexOf(“demo.adxstudio.com”) != -1 ? document.location.pathname.split(“/”).slice(0, 3).join(“/”) : “”) + ‘/Cache.axd?Message=InvalidateAll&d=’ + (new Date()).valueOf();
var req = new XMLHttpRequest();
req.open(‘GET’, url, false);
req.send(null);
// Redirect to Portal Home Page
window.location.href = ‘../’;
});

  • In below screen, I created a new Web Page ‘Portal Cache Clear’ and copied the above script.

ADX Cache_2

  • So, to invalidate ‘Cache’ on the ‘Submit’ of any of your Portal form, In Entity Form’s ‘On Success Settings’, Redirect to Cache ‘Web Page’ as configured in below screen.

ADX Cache_3

  • That’s it. Your portal should invalidate cache, up on Entity Form submission. One caveat of this approach is, ‘Portal Cache’ web page will flash for few seconds before redirecting to portal’s ‘Home’ page.

Note:

  • This Information is Relevant to Legacy Adxstudio Portals Only.
  • Dynamics 365 Portal Add-on’s Do Not Require this Configuration.

🙂

 

 

Categories: ADX Tags: ,