Sdl.Web.Tridion/Mapping/ModelBuilderPipeline.cs
/// <summary>
/// Creates a Strongly Typed Page Model for a given DXA R2 Data Model.
/// </summary>
/// <param name="pageModelData">The DXA R2 Data Model.</param>
/// <param name="includePageRegions">Indicates whether Include Page Regions should be included.</param>
/// <param name="localization">The context <see cref="ILocalization"/>.</param>
/// <returns>The Strongly Typed Page Model (an instance of class <see cref="PageModel"/> or a subclass).</returns>
Creates a Strongly Typed Page Model for a given DXA R2 Data Model.
Creates a Strongly Typed Page Model for a given DXA R2 Data Model .
public static PageModel CreatePageModel(PageModelData pageModelData, bool includePageRegions,
            ILocalization localization)
        {
            using (new Tracer(pageModelData, localization))
            {
                PageModel pageModel = null;
                if (CacheRegions.IsViewModelCachingEnabled) 
                {
                    string key = $"{pageModelData.Id}-{includePageRegions}-{localization.Id}";
                    PageModel cachedPageModel = SiteConfiguration.CacheProvider.GetOrAdd(
                       key,
                       CacheRegions.PageModel,
                       () =>
                       {
                           pageModel = CreatePageModelInternal(pageModelData, includePageRegions, localization);
                           if (pageModel.NoCache || pageModel.IsVolatile || pageModel.HasNoCacheAttribute)
                           {
                               Log.Trace($"PageModel with id={pageModelData.Id} MvcData={pageModel.MvcData} includePageRegions={includePageRegions} localization={localization.Id} was marked for no caching.");
                               return null;
                           }
                           Log.Trace($"PageModel with id={pageModelData.Id} MvcData={pageModel.MvcData} includePageRegions={includePageRegions} localization={localization.Id} added to cache.");
                           return pageModel;
                       }
                       );
                    if (cachedPageModel != null)
                    {
                        pageModel = (PageModel)cachedPageModel.DeepCopy();
                    }
                }
                else
                {
                    pageModel = CreatePageModelInternal(pageModelData, includePageRegions, localization);
                }
                return pageModel;
            }
        }
public static PageModel CreatePageModel ( PageModelData pageModelData , bool includePageRegions , ILocalization localization ) { using ( new Tracer ( pageModelData , localization ) ) { PageModel pageModel = null ; if ( CacheRegions . IsViewModelCachingEnabled ) { string key = $" { pageModelData . Id } - { includePageRegions } - { localization . Id } " ; PageModel cachedPageModel = SiteConfiguration . CacheProvider . GetOrAdd ( key , CacheRegions . PageModel , ( ) => { pageModel = CreatePageModelInternal ( pageModelData , includePageRegions , localization ) ; if ( pageModel . NoCache || pageModel . IsVolatile || pageModel . HasNoCacheAttribute ) { Log . Trace ( $" PageModel with id= { pageModelData . Id }  MvcData= { pageModel . MvcData }  includePageRegions= { includePageRegions }  localization= { localization . Id }  was marked for no caching. " ) ; return null ; } Log . Trace ( $" PageModel with id= { pageModelData . Id }  MvcData= { pageModel . MvcData }  includePageRegions= { includePageRegions }  localization= { localization . Id }  added to cache. " ) ; return pageModel ; } ) ; if ( cachedPageModel != null ) { pageModel = ( PageModel ) cachedPageModel . DeepCopy ( ) ; } } else { pageModel = CreatePageModelInternal ( pageModelData , includePageRegions , localization ) ; } return pageModel ; } }
Creates a Strongly Typed Page Model for a given DXA R2 Data Model.
Creates a Strongly Typed Page Model for a given DXA R2 Data Model .
// quick way to avoid all caching on viewmodels // this page has been marked to no caching so we return null to prevent a cache write                                // don't return the cached Page Model itself, because we don't want dynamic logic to modify the cached state.
The Strongly Typed Page Model (an instance of class  or a subclass).
The Strongly Typed Page Model ( an instance of class or a subclass ) .
pageModelData
PageModelData
The DXA R2 Data Model.
The DXA R2 Data Model .
includePageRegions
bool
Indicates whether Include Page Regions should be included.
Indicates whether Include Page Regions should be included .
localization
ILocalization
The context .
The context .