示例#1
0
        private IEnumerable <SyndicationItem> GetFromCacheOrFactory(SyndicationItemFactory syndicationFactory, SyndicationFeedPageType currentPage, IEnumerable <Category> parsedCategories)
        {
            var cacheTime = currentPage.CacheFeedforSeconds;

            string categoryQuery = string.Empty;

            foreach (var category in parsedCategories)
            {
                categoryQuery += category.Name;
            }

            var cacheKey = string.Format("SyndicationFeedPageType_{0}_{1}", currentPage.ContentLink.ToString(), categoryQuery);

            var cachedItems = CacheManager.Get(cacheKey) as IEnumerable <SyndicationItem>;

            if (cachedItems == null)
            {
                cachedItems = syndicationFactory.GetSyndicationItems();

                if (cacheTime > 0)
                {
                    var cachePolicy = new CacheEvictionPolicy(new[] { DataFactoryCache.PageCommonCacheKey(currentPage.ContentLink) }
                                                              , new TimeSpan(0, 0, cacheTime),
                                                              CacheTimeoutType.Absolute);

                    CacheManager.Insert(cacheKey, syndicationFactory.GetSyndicationItems(), cachePolicy);
                }
            }

            return(cachedItems);
        }
示例#2
0
        protected override void SetCacheSettings(ContentReference contentReference, IEnumerable <ContentReference> children, CacheSettings cacheSettings)
        {
            // Make the cache of this content provider depend on the original content

            cacheSettings.CacheKeys.Add(DataFactoryCache.PageCommonCacheKey(new ContentReference(contentReference.ID)));

            foreach (var child in children)
            {
                cacheSettings.CacheKeys.Add(DataFactoryCache.PageCommonCacheKey(new ContentReference(child.ID)));
            }
        }
        /// <summary>
        /// The set cache settings.
        /// </summary>
        /// <param name="content">
        /// The content.
        /// </param>
        /// <param name="cacheSettings">
        /// The cache settings.
        /// </param>
        protected override void SetCacheSettings(IContent content, CacheSettings cacheSettings)
        {
            if (content == null || cacheSettings == null)
            {
                return;
            }

            // Make the cache of this content provider depend on the original content
            cacheSettings.CacheKeys.Add(
                DataFactoryCache.PageCommonCacheKey(new ContentReference(content.ContentLink.ID)));
        }
        /// <summary>
        /// The set cache settings.
        /// </summary>
        /// <param name="contentReference">
        /// The content reference.
        /// </param>
        /// <param name="children">
        /// The children.
        /// </param>
        /// <param name="cacheSettings">
        /// The cache settings.
        /// </param>
        protected override void SetCacheSettings(
            ContentReference contentReference, IEnumerable <ContentReference> children, CacheSettings cacheSettings)
        {
            if (ContentReference.IsNullOrEmpty(contentReference) || children == null || cacheSettings == null)
            {
                return;
            }

            // Make the cache of this content provider depend on the original content
            cacheSettings.CacheKeys.Add(DataFactoryCache.PageCommonCacheKey(new ContentReference(contentReference.ID)));

            foreach (ContentReference child in children)
            {
                cacheSettings.CacheKeys.Add(DataFactoryCache.PageCommonCacheKey(new ContentReference(child.ID)));
            }
        }
        public override IEnumerable <SearchResult> Search(Query query)
        {
            var searchResults = new List <SearchResult>();

            // Clear previous search results
            _youTubeProvider.SearchResult.Clear();

            foreach (var item in _youTubeRepository.Search(query.SearchQuery))
            {
                if (item.id.kind == "youtube#video")
                {
                    var mappedIdentity      = _identityMappingService.Get(MappedIdentity.ConstructExternalIdentifier(_youTubeProvider.ProviderKey, string.Format("video/{0}/{1}", _youTubeProvider.SearchResultNode.ID, item.id.videoId)), true);
                    var youTubeSearchResult = _youTubeProvider.CreateSearchResult(mappedIdentity, item);
                    searchResults.Add(CreateSearchResult(youTubeSearchResult));
                    _youTubeProvider.SearchResult.Add(youTubeSearchResult);
                }
            }

            // Clear child items from the search node
            DataFactoryCache.RemoveListing(_youTubeProvider.SearchResultNode);

            return(searchResults);
        }
示例#6
0
        public virtual PageData ConvertToTyped(PageData page)
        {
            Type type        = GetPageTypeType(page.PageTypeID);
            var  castingTest = page as TypedPageData;

            if (type == null || castingTest != null)
            {
                if (type != null)
                {
                    if (_logger.IsDebugEnabled)
                    {
                        _logger.Debug(string.Format("Cache hit on {0}", type.Name));
                    }
                }

                return(page);
            }

            var populated = Activator.CreateAndPopulateTypedInstance(page, type);

            if (page.WorkPageID != 0)
            {
                if (_logger.IsDebugEnabled)
                {
                    _logger.Debug(string.Format("Skipping page with work ID {0}", page.WorkPageID));
                }

                return(populated);
            }

            // Save to cache if its a final published version
            var pageProvider  = DataFactory.Instance.GetPageProvider(page.PageLink);
            var cacheSettings = new CacheSettings(PageCacheTimeout);

            if (_logger.IsDebugEnabled)
            {
                _logger.Debug(string.Format("Saving to cache {0}", type.Name));
            }

            string key  = DataFactoryCache.PageCommonCacheKey(page.PageLink);
            string str2 = DataFactoryCache.PageLanguageCacheKey(page.PageLink, page.LanguageBranch);

            if (cacheSettings.CancelCaching)
            {
                CacheManager.RemoveLocalOnly(key);
            }
            else
            {
                if (CacheManager.RuntimeCacheGet(key) == null)
                {
                    CacheManager.RuntimeCacheInsert(key, DateTime.UtcNow.Ticks, new CacheDependency(null, new string[] { "DataFactoryCache.MasterKey", pageProvider.ProviderCacheKey }), Cache.NoAbsoluteExpiration, PageCacheTimeout);
                }
                string[]      filenames = (cacheSettings.FileNames.Count > 0) ? cacheSettings.FileNames.ToArray() : null;
                List <string> list      = new List <string>(new string[] { "DataFactoryCache.MasterKey", pageProvider.ProviderCacheKey, key });
                list.AddRange(cacheSettings.CacheKeys);
                if (page.IsMasterLanguageBranch)
                {
                    CacheManager.RuntimeCacheInsert(DataFactoryCache.PageMasterLanguageCacheKey(page.PageLink), populated, new CacheDependency(filenames, list.ToArray()), cacheSettings.AbsoluteExpiration, cacheSettings.SlidingExpiration);
                }
                CacheManager.RuntimeCacheInsert(str2, populated, new CacheDependency(filenames, list.ToArray()), cacheSettings.AbsoluteExpiration, cacheSettings.SlidingExpiration);
            }

            return(populated);
        }