public PageDataCollection List(PageReference pageLink)
        {
            string key = CachedFindPagesWithCriterion.GetCacheKey(pageLink.ToReferenceWithoutVersion());

            var standardPages = _synchronizedObjectInstanceCache.Get(key) as PageDataCollection;
            if (standardPages == null)
            {
                object miniLock = MiniLocks.GetOrAdd(key, k => new object());
                lock (miniLock)
                {
                    standardPages = _synchronizedObjectInstanceCache.Get(key) as PageDataCollection;
                    if (standardPages == null)
                    {
                        string pageTypeId = _pageTypeRepository.Load<StandardPage>()?.ID.ToString();
                        if (pageTypeId == null)
                        {
                            return new PageDataCollection();
                        }

                        PropertyCriteria productPageTypeCriterion = new PropertyCriteria
                        {
                            Name = "PageTypeID",
                            Type = PropertyDataType.PageType,
                            Value = pageTypeId,
                            Condition = CompareCondition.Equal,
                            Required = true
                        };

                        var criteria = new PropertyCriteriaCollection
                        {
                            productPageTypeCriterion
                        };

                        standardPages = _searchPages.FindPagesWithCriteria(pageLink, criteria);

                        Thread.Sleep(5000);

                        _synchronizedObjectInstanceCache.Insert(key, standardPages, CacheEvictionPolicy.Empty);

                        // Saving some space we will release the lock
                        object temp1;
                        if (MiniLocks.TryGetValue(key, out temp1) && (temp1 == miniLock))
                        {
                            object temp2;
                            MiniLocks.TryRemove(key, out temp2);
                        }
                    }
                }
            }

            return standardPages;
        }
Example #2
0
        protected PageData GetPage(PageReference pageRef)
        {
            IContentRepository contentRepository = ServiceLocator.Current.GetInstance <IContentRepository>();

            ContentReference contentLink = pageRef.ToReferenceWithoutVersion();
            PageData         pageData    = contentRepository.Get <PageData>(contentLink);

            if (pageData == null)
            {
                throw new NullReferenceException("Cannot Load Page: " + pageRef.ToString());
            }

            return(pageData);
        }
        public PageDataCollection List(PageReference pageLink)
        {
            string cacheKey = CachedFindPagesWithCriterion.GetCacheKey(pageLink.ToReferenceWithoutVersion());

            var standardPages = _synchronizedObjectInstanceCache.Get(cacheKey) as PageDataCollection;
            if (standardPages == null)
            {
                lock (Lock)
                {
                    // Check cache again since standardPages might have been cached while waiting for the lock to open
                    standardPages = _synchronizedObjectInstanceCache.Get(cacheKey) as PageDataCollection;
                    if (standardPages == null)
                    {
                        string pageTypeId = _pageTypeRepository.Load<StandardPage>()?.ID.ToString();
                        if (pageTypeId == null)
                        {
                            return new PageDataCollection();
                        }

                        PropertyCriteria productPageTypeCriterion = new PropertyCriteria
                        {
                            Name = "PageTypeID",
                            Type = PropertyDataType.PageType,
                            Value = pageTypeId,
                            Condition = CompareCondition.Equal,
                            Required = true
                        };

                        var criteria = new PropertyCriteriaCollection
                        {
                            productPageTypeCriterion
                        };

                        standardPages = _searchPages.FindPagesWithCriteria(pageLink, criteria);

                        Thread.Sleep(5000);

                        _synchronizedObjectInstanceCache.Insert(cacheKey, standardPages, CacheEvictionPolicy.Empty);
                    }
                }
            }

            return standardPages;
        }
        public PageDataCollection List(PageReference pageLink)
        {
            string cacheKey = GetCacheKey(pageLink.ToReferenceWithoutVersion());

            var standardPages = _synchronizedObjectInstanceCache.Get(cacheKey) as PageDataCollection;
            if (standardPages == null)
            {
                string pageTypeId = _pageTypeRepository.Load<StandardPage>()?.ID.ToString();
                if (pageTypeId == null)
                {
                    return new PageDataCollection();
                }

                PropertyCriteria productPageTypeCriterion = new PropertyCriteria
                {
                    Name = "PageTypeID",
                    Type = PropertyDataType.PageType,
                    Value = pageTypeId,
                    Condition = CompareCondition.Equal,
                    Required = true
                };

                var criteria = new PropertyCriteriaCollection
                {
                    productPageTypeCriterion
                };

                standardPages = _searchPages.FindPagesWithCriteria(pageLink, criteria);

                // Lots of things can happen while fetching the cache
                Thread.Sleep(1000);

                // Actually caching the ContentData is not a good practice. Caching the ContentReference is  better
                _synchronizedObjectInstanceCache.Insert(cacheKey, standardPages, CacheEvictionPolicy.Empty);
            }

            return standardPages;
        }
Example #5
0
        protected PageData GetPage(PageReference pageRef)
        {
            IContentRepository contentRepository = ServiceLocator.Current.GetInstance<IContentRepository>();

            ContentReference contentLink = pageRef.ToReferenceWithoutVersion();
            PageData pageData = contentRepository.Get<PageData>(contentLink);
            if (pageData == null)
            {
                throw new NullReferenceException("Cannot Load Page: " + pageRef.ToString());
            }

            return pageData;
        }