Support Portal ContactGet in touch

Planning a Round Trip – Portal Caching

   Words by CRM Consultancy

   on 05/11/2015 10:00:00

Planning a Round Trip - Portal CachingThe Portal Framework allows us to retrieve a CRM Record from CRM and present into our Webpage using standard Mark-up.

So if we examine the following ASPX Mark-up:

<crmcs:CRMRecordArea ID="HeaderBar" EntityType="cw_workitem" ReadOnly="true" Cached="true" EnableViewState="false" runat="server">
    <crmcs:CRMLabel CRMField="cw_caseid" ID="HeaderBar_cw_caseid" runat="server" /> >>
    <crmcs:CRMLabel CRMField="regardingobjectid" ID="HeaderBar_regardingobjectid" runat="server" /> >>
    <crmcs:CRMLabel CRMField="cw_workitemtypeid" ID="HeaderBar_cw_workitemtypeid" runat="server" /> >>
    Checklist
</crmcs:CRMRecordArea>

This will retrieve the ‘cw_workitem’ Work Instruction record from CRM and present the fields accordingly.

To do this, the Framework will examine the fields required and manage performance by only retrieving these fields from CRM using a limited Column Set.  Specifically in our example only retrieving the following attributes from CRM: cw_caseid, regardingobjectid and cw_workitemtypeid.

This is important as reading data back from the CRM Webservice as this is typically the most costly element when loading the Portal Page for the End-User, so we should always try and minimise this cost by limiting the Column Set being pulled from CRM, and the Portal Framework helps with this by reviewing the controls and building the column set accordingly.

For Editable Fields and Controls, the page will only need to retrieve the editable Columns from CRM once, as after which the values edited by the user will then be stored on the Webpage or in Viewstate between the client and our Portal Webserver.

This gives us the concept of the ‘round-trip’ where data is read to the Portal from CRM, sent to the client in the page, updated by the user and then posted back to the Portal via Viewstate. (which would then typically save or update back to CRM)

This Round-Trip between the Client and Server is by no means unique to CRM and gives us the basic pattern that most websites use. (whether this be in the form of Full or Partial Postbacks, or AJAX implementations)Client - Server Round Trip

However if we look at the example of a Read-Only control, we would typically here disable Viewstate to avoid the performance cost in the page constantly submitting Viewstate Request back from client when the values cannot have changed – disabling Viewstate here stops this ‘round-trip’ postback to improve performance.

<crmcs:CRMRecordArea ID="HeaderBar" EntityType="incident" ReadOnly="true" EnableViewState="false" runat="server">

Yet whilst disabling Viewstate improves performance between the client and server, this does instead force the page to reload the values entirely on each Postback – and as such, re-retrieve the values from CRM, which can result in a similar performance cost.

Only this time the Round Trip is instead server-to-server between the Portal and CRM.Round Trip from a Client to a Portal Page followed by a Round Trip from the Portal to Dynamics CRM

To avoid this cost, we can use activate caching in the CRM Area Control.

<crmcs:CRMRecordArea ID="HeaderBar" EntityType="incident" ReadOnly="true" Cached="true" EnableViewState="false" runat="server">

With the first load of the page, this prompts the control to read the initial values from the CRM Service in the usual fashion, but also store the values in the Portal Cache.

On subsequent Postbacks, the control then improves performance by consulting the cache to read the static values directly rather than invoking this round-trip from the Portal Server to CRM.

Caching can then vastly improve the performance of our Portal Page, and fortunately is easy to enable and use within the framework for the CRM Record Area control.

Other Caching within the Framework

When using the Framework to present CRM Option Set Controls or CRM Lookup Controls, by default the Framework will cache the possible values to prevent the page reading from CRM on each page load or postback.

So if looked at the following control:

<crmcs:CRMOptionSet ID="casetypecode" CRMField="casetypecode" class="large" runat="server"></crmcs:CRMOptionSet>

When first loaded, this control will load the possible Option Set values from CRM, and write these values into the cache.

Type of Ticket Option Set - Example of a cached Option Set field presented via the Framework

Example of a cached Option Set field presented via the Framework

So when the page is posted back or refreshed by the user, the Option Set values are reloaded from the cache and so the round-trip from the Portal to CRM to read the values is prevented to help improve performance.

Application vs Session Caching

When thinking about caching for web applications, there is two types of cache available to us:

The Session Cache, this is where the web application identifies each unique session or site visitor and maintains a cache within that session.  This would typically be used for authenticated sites that maintain (in some shape for form, whether this be ADFS or Form-based) a User Login to manage the user’s identity as they browse between different pages or services within the application – and this type of cache can be useful for storing values specific to that user, such as their Email Address or their Security Rights as these are then stored in a cache specific to that user.

The Application Cache, this is where the web application caches values globally across the Web Application.  This would typically be used for global values or lists that pages or services may depend upon across multiple users.

So in our example above for storing an existing set of Option Set values within the cache, this would be stored into the Application Cache so multiple users can benefit from the performance increase of loading the Option Set from cache as opposed to the round-trip to CRM.

However for both individual controls and CRM Record Areas, we can specify this setting to control which type of cache is used:

<crmcs:CRMOptionSet ID="casetypecode" CRMField="casetypecode" class="large" CacheType=”Session” runat="server"></crmcs:CRMOptionSet>

This allows us to control whether the Session, Application or No Cache is used for each control or record area.

Custom Caching

This caching works within the Framework to allow us to quickly specify how a control or area manages round-trips to CRM vs the cache – however taking this outside the controls provided by the framework, we can also store other values or objects in the cache to help build custom logic within our Portal Pages:

TeamUserList teams = null;
TeamUserList teamUsers = null;
if (_defaultRecord != null)
{
    if (_defaultRecord.Type.Equals("systemuser"))
    {
        teams = CRMCS.Portalbaseline.CacheFactory.Create(Portalbaseline.CacheType.httpCache).Get<TeamUserList>(
            "User[" + _defaultRecord.Id + "]_Teams",
            () => TeamUserHelper.GetTeamsForUser(_service, _defaultRecord.Id));               
    }
}

This allows us to store custom sets of values in the Session or Application cache to help our page, so in the above example, this loads the list of CRM Teams that a CRM User is a member of and then stores this in the Session Cache for future reference by that User.

Diary Screen in CRM - viewing the list of Users within a Team and storing in the Session Cache

Viewing the list of Users within a Team and storing in the Session Cache

Further Reading

Whilst this article concerns the caching built into the CRMCS Framework for developing Portals and Custom Screens for CRM, this concept of caching is universal for Web Development and the core ASP.NET Framework, and as such has a wealth of articles and technical guides for further reading:

Difference between Session and Caching

https://www.c-sharpcorner.com/UploadFile/75a48f/difference-between-session-and-caching/

Caching and Session in ASP.NET

https://stvault.net/post/caching-and-session-in-asp-net-part-1

MSDN - ASP.NET Caching

https://msdn.microsoft.com/en-us/library/xsbfdd8c.aspx

Share this Article

Search Articles

Filter Articles

CRM Tech DocMan

Recent Articles

CRMCS Quick Start Guide: How To Produce a Microsoft Teams Live Event Dynamics 365 Marketing: Lead Scoring and Sales Acceptance Designing and Developing Microsoft Power Apps Portals Thank You for Attending CRMCS’ Webinar - Achieving B2B sales excellence with Dynamics 365 & Microsoft Teams Thank You for Attending Our Webinar - Achieving B2B sales excellence with Dynamics 365 & Microsoft Teams Webinar: Discover How CRMCS Have United Dynamics 365, SharePoint and Microsoft Teams To Create Sales Excellence Ignite your workflow by adding DocDrive365 to Office 365 The CRMCS guide to everything you need to know about integrating Teams with Dynamics 365 Saving Time By Keeping Documents In One Place TDE Database Encryption with On Premise Dynamics The Key to Successful Compliance in 2020 Part 2: Let’s get GDPR Compliant with Microsoft Power Automate Top 3 Essential Tips for Remote Working Dynamics 365 Marketing: Top 5 Best Features Dynamics Day in the Life - Puma Investments Can you use Teams to amplify collaboration in Dynamics? Part 1: Using a Scheduled Power Automate to Trigger Expiry Date Reminders The secrets of successful document collaboration in Dynamics CRMCS launches new AppSource approved DocDrive365 Dynamics Day in the Life - Moneypenny Release Management Add the App to Dynamics DocDrive365 Security: Day One - Getting Started with Dynamics to SharePoint Permissions Building a New Scheduled Process using Flow
  • "Paul has made a real difference to how my team of 24 people record and store valuable customer data and sales opportunities. Highly recommended."

    James, Operations Director

  • "Understanding your business allows us to advise when to implement aspects of CRM and, likewise, when not to."

    Paul McQuillan, Managing Director

  • "Dynamics 365 and CRMCS have made a real lasting difference to our business, allowing us to replace older systems that were holding back our performance."

    Grahame, Chief Operating Officer

  • "James worked well with us to help connect CRM with Outlook and relate how this might benefit our team using CRM for Property Care."

    Natalie, Property Care Supervisor

  • "Matt was really good with helping us run User Testing on the new Compliance Module of our CRM System."

    Tom, Compliance Administrator

Prefer to go old-school?

Write to us using the below addresses.

Head Office
CRM Consultancy
61 Oxford Street
Manchester
M1 6EQ

London Office
CRM Consultancy London
Grosvenor Avenue
London

Content © CRM Consultancy.