Sdl.Web.Tridion/Providers/ModelService/ModelService.cs
/// <summary>
/// Gets a Page Model for a given Page Id.
/// </summary>
/// <param name="pageId">Page Id</param>
/// <param name="localization">The context Localization.</param>
/// <param name="addIncludes">Indicates whether include Pages should be expanded.</param>
/// <returns>The Page Model.</returns>
/// <exception cref="DxaItemNotFoundException">If no Page Model exists for the given Id.</exception>
Gets a Page Model for a given Page Id.
Gets a Page Model for a given Page Id .
public PageModel GetPageModel(int pageId, ILocalization localization, bool addIncludes = true)
        {
            using (new Tracer(localization.Id, pageId, localization, addIncludes))
            {
                PageModel result = null;
                if (CacheRegions.IsViewModelCachingEnabled)
                {
                    PageModel cachedPageModel = SiteConfiguration.CacheProvider.GetOrAdd(
                        $"{localization.Id}-{pageId}:{addIncludes}", 
                        CacheRegions.PageModel,
                        () =>
                        {
                            PageModel pageModel = LoadPageModel(pageId, addIncludes, localization);
                            if (pageModel.NoCache)
                            {
                                result = pageModel;
                                return null;
                            }
                            return pageModel;
                        }
                        );
                    if (cachedPageModel != null)
                    {
                        result = (PageModel)cachedPageModel.DeepCopy();
                    }
                }
                else
                {
                    result = LoadPageModel(pageId, addIncludes, localization);
                }
                if (SiteConfiguration.ConditionalEntityEvaluator != null)
                {
                    result.FilterConditionalEntities(localization);
                }
                return result;
            }
        }
public PageModel GetPageModel ( int pageId , ILocalization localization , bool addIncludes = true ) { using ( new Tracer ( localization . Id , pageId , localization , addIncludes ) ) { PageModel result = null ; if ( CacheRegions . IsViewModelCachingEnabled ) { PageModel cachedPageModel = SiteConfiguration . CacheProvider . GetOrAdd ( $" { localization . Id } - { pageId } : { addIncludes } " , CacheRegions . PageModel , ( ) => { PageModel pageModel = LoadPageModel ( pageId , addIncludes , localization ) ; if ( pageModel . NoCache ) { result = pageModel ; return null ; } return pageModel ; } ) ; if ( cachedPageModel != null ) { result = ( PageModel ) cachedPageModel . DeepCopy ( ) ; } } else { result = LoadPageModel ( pageId , addIncludes , localization ) ; } if ( SiteConfiguration . ConditionalEntityEvaluator != null ) { result . FilterConditionalEntities ( localization ) ; } return result ; } }
Gets a Page Model for a given Page Id.
Gets a Page Model for a given Page Id .
// Cache Page Models with and without includes separately // Don't return the cached Page Model itself, because we don't want dynamic logic to modify the cached state.
The Page Model.
The Page Model .
If no Page Model exists for the given Id.
If no Page Model exists for the given Id .
pageId
int
None
localization
ILocalization
The context Localization.
The context Localization .
addIncludes
bool
Indicates whether include Pages should be expanded.
Indicates whether include Pages should be expanded .