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); }
public ActionResult Index(SyndicationFeedPageType currentPage, string categories) { var parsedCategories = ParseCategories(categories); var feedContext = new SyndicationFeedContext(currentPage, parsedCategories.ToList()); var siteUrl = SiteDefinition.Current.SiteUrl.ToString().TrimEnd('/'); var currentUri = new Uri(siteUrl + UrlResolver.Current.GetUrl(currentPage.ContentLink)); var syndicationFactory = new SyndicationItemFactory(ContentLoader, FeedContentResolver, FeedFilterer, ItemDescriptionProvider, ItemModifier, feedContext); var items = GetFromCacheOrFactory(syndicationFactory, currentPage, parsedCategories); var feed = new SyndicationFeed { Items = items, Id = siteUrl + UrlResolver.Current.GetUrl(ContentReference.StartPage), Title = new TextSyndicationContent(currentPage.PageName), Description = new TextSyndicationContent(currentPage.Description), Language = currentPage.LanguageBranch, Generator = "http://nuget.episerver.com/en/OtherPages/Package/?packageId=Chief2moro.SyndicationFeeds" }; feed.Links.Add(new SyndicationLink() { Uri = currentUri, RelationshipType = "self" }); if (currentPage.Category != null) { var categoryRepository = ServiceLocator.Current.GetInstance <CategoryRepository>(); foreach (var category in currentPage.Category) { feed.Categories.Add(new SyndicationCategory(categoryRepository.Get(category).Description)); } } if (feed.Items.Any()) { feed.LastUpdatedTime = feed.Items.Max(m => m.LastUpdatedTime); } if (currentPage.FeedFormat == FeedFormat.Atom) { return(new AtomActionResult(feed)); } return(new RssActionResult(feed)); }
public ActionResult Index(SyndicationFeedPageType currentPage) { var syndicationFactory = new SyndicationItemFactory(ContentLoader, FeedContentResolver, currentPage); var feed = new SyndicationFeed { Items = syndicationFactory.GetSyndicationItems(), Id = currentPage.ContentGuid.ToString(), Title = new TextSyndicationContent(currentPage.PageName), Description = new TextSyndicationContent(currentPage.Description), }; if (feed.Items.Any()) { feed.LastUpdatedTime = feed.Items.Max(m => m.LastUpdatedTime); } if (currentPage.FeedFormat == FeedFormat.Atom) { return(new AtomActionResult(feed)); } return(new RssActionResult(feed)); }