improve cache
This commit is contained in:
@@ -9,15 +9,17 @@ using DotNetMashup.Web.Global;
|
|||||||
using DotNetMashup.Web.Model;
|
using DotNetMashup.Web.Model;
|
||||||
using DotNetMashup.Web.ViewModel;
|
using DotNetMashup.Web.ViewModel;
|
||||||
using Microsoft.AspNet.Mvc;
|
using Microsoft.AspNet.Mvc;
|
||||||
|
using Microsoft.Framework.Caching.Memory;
|
||||||
|
|
||||||
namespace DotNetMashup.Web.Controllers
|
namespace DotNetMashup.Web.Controllers
|
||||||
{
|
{
|
||||||
public class HomeController : Controller
|
public class HomeController : Controller
|
||||||
{
|
{
|
||||||
|
private readonly IMemoryCache cache;
|
||||||
private readonly ISiteSetting setting;
|
private readonly ISiteSetting setting;
|
||||||
private readonly Factory.RepositoryFactory factory;
|
private readonly Factory.RepositoryFactory factory;
|
||||||
|
|
||||||
public HomeController(Factory.RepositoryFactory factory, ISiteSetting setting)
|
public HomeController(Factory.RepositoryFactory factory, ISiteSetting setting, IMemoryCache cache)
|
||||||
{
|
{
|
||||||
if(factory == null)
|
if(factory == null)
|
||||||
{
|
{
|
||||||
@@ -29,9 +31,9 @@ namespace DotNetMashup.Web.Controllers
|
|||||||
}
|
}
|
||||||
this.factory = factory;
|
this.factory = factory;
|
||||||
this.setting = setting;
|
this.setting = setting;
|
||||||
|
this.cache = cache;
|
||||||
}
|
}
|
||||||
|
|
||||||
[ResponseCache(Duration = 3600, NoStore = true, Location = ResponseCacheLocation.Any)]
|
|
||||||
public async Task<IActionResult> Index(int page = 1)
|
public async Task<IActionResult> Index(int page = 1)
|
||||||
{
|
{
|
||||||
var factoryData = (await factory.GetData());
|
var factoryData = (await factory.GetData());
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ namespace DotNetMashup.Web.Extensions
|
|||||||
Title = new TextSyndicationContent(settings.Title),
|
Title = new TextSyndicationContent(settings.Title),
|
||||||
Id = "DotNet Mashup",
|
Id = "DotNet Mashup",
|
||||||
LastUpdatedTime = data.OrderByDescending(a => a.PublishedDate).FirstOrDefault().PublishedDate,
|
LastUpdatedTime = data.OrderByDescending(a => a.PublishedDate).FirstOrDefault().PublishedDate,
|
||||||
Description = new TextSyndicationContent(settings.Descriptions)
|
Description = new TextSyndicationContent(settings.Descriptions),
|
||||||
};
|
};
|
||||||
var authors = data.Select(a => a.Author)
|
var authors = data.Select(a => a.Author)
|
||||||
.Distinct()
|
.Distinct()
|
||||||
@@ -25,7 +25,7 @@ namespace DotNetMashup.Web.Extensions
|
|||||||
authors.ForEach(a => feed.Authors.Add(a));
|
authors.ForEach(a => feed.Authors.Add(a));
|
||||||
authors.ForEach(a => feed.Contributors.Add(a));
|
authors.ForEach(a => feed.Contributors.Add(a));
|
||||||
feed.Links.Add(new SyndicationLink(new Uri("http://dotnetmashup.azurewebsites.net")));
|
feed.Links.Add(new SyndicationLink(new Uri("http://dotnetmashup.azurewebsites.net")));
|
||||||
feed.Items = data.Select(a => new SyndicationItem(a.Title, a.Content, a.OriginalLink)).ToList();
|
feed.Items = data.Select(a => new SyndicationItem(a.Title, a.Content, a.OriginalLink) { PublishDate = a.PublishedDate }).ToList();
|
||||||
|
|
||||||
return feed;
|
return feed;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ namespace DotNetMashup.Web.Extensions
|
|||||||
{
|
{
|
||||||
PublishedDate = tweet.CreatedAt,
|
PublishedDate = tweet.CreatedAt,
|
||||||
Content = tweet.Text,
|
Content = tweet.Text,
|
||||||
|
OriginalLink = new Uri($"https://twitter.com/statuses/{tweet.Id}"),
|
||||||
tweet = new Lazy<Task<IOEmbedTweet>>(() => tweet.GenerateOEmbedTweetAsync()),
|
tweet = new Lazy<Task<IOEmbedTweet>>(() => tweet.GenerateOEmbedTweetAsync()),
|
||||||
Author = new Author
|
Author = new Author
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -38,8 +38,8 @@
|
|||||||
var loading = false;
|
var loading = false;
|
||||||
$(window).on('scroll', function () {
|
$(window).on('scroll', function () {
|
||||||
var loadingImage = $('.loadWheel');
|
var loadingImage = $('.loadWheel');
|
||||||
var tile = $('.tile').last();
|
var tile = $('.tileRow').last();
|
||||||
if($(window).scrollTop() + tile.height() + 150 >= tile.position().top && !loading ) {
|
if($(window).scrollTop() + tile.height() + 250 >= tile.position().top && !loading ) {
|
||||||
loading = true
|
loading = true
|
||||||
loadingImage.show();
|
loadingImage.show();
|
||||||
$.ajax('/Home/Tiles', {data:{page:page+1}})
|
$.ajax('/Home/Tiles', {data:{page:page+1}})
|
||||||
@@ -50,7 +50,7 @@
|
|||||||
var resd = $(data);
|
var resd = $(data);
|
||||||
resd.find('img').addClass('img-responsive');
|
resd.find('img').addClass('img-responsive');
|
||||||
$('#tilesContainer').append(resd).find('.tile').addClass('show');
|
$('#tilesContainer').append(resd).find('.tile').addClass('show');
|
||||||
|
|
||||||
})
|
})
|
||||||
.error(function(){
|
.error(function(){
|
||||||
loadingImage.hide();
|
loadingImage.hide();
|
||||||
@@ -58,8 +58,6 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
}
|
}
|
||||||
@@ -1,9 +1,4 @@
|
|||||||
@model DotNetMashup.Web.Model.TwitterData
|
@model DotNetMashup.Web.Model.TwitterData
|
||||||
|
<div class="col-md-offset-3">
|
||||||
<cache vary-by="@Model.GetHashCode()">
|
@Html.Raw((await Model.tweet.Value)?.HTML)
|
||||||
<div class="row">
|
</div>
|
||||||
<div class="col-md-offset-3">
|
|
||||||
@Html.Raw((await Model.tweet.Value)?.HTML)
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</cache>
|
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
@model DotNetMashup.Web.Model.IExternalData
|
@model DotNetMashup.Web.Model.IExternalData
|
||||||
|
<cache vary-by="@Model.GetHashCode()">
|
||||||
@Html.DisplayFor(a => a)
|
@Html.DisplayFor(a => a)
|
||||||
|
</cache>
|
||||||
@@ -21,7 +21,7 @@
|
|||||||
<footer>
|
<footer>
|
||||||
<p>© 2015 - DotNetMashup.Web</p>
|
<p>© 2015 - DotNetMashup.Web</p>
|
||||||
</footer>
|
</footer>
|
||||||
|
<a href="https://github.com/tparnell8/DotNetMashup"><img style="position: absolute; top: 0; right: 0; border: 0; z-index: 99999999" src="https://camo.githubusercontent.com/38ef81f8aca64bb9a64448d0d70f1308ef5341ab/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f6461726b626c75655f3132313632312e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png"></a>
|
||||||
<script src="https://ajax.aspnetcdn.com/ajax/jquery/jquery-2.1.4.min.js"
|
<script src="https://ajax.aspnetcdn.com/ajax/jquery/jquery-2.1.4.min.js"
|
||||||
asp-fallback-src="~/lib/jquery/dist/jquery.min.js"
|
asp-fallback-src="~/lib/jquery/dist/jquery.min.js"
|
||||||
asp-fallback-test="window.jQuery">
|
asp-fallback-test="window.jQuery">
|
||||||
|
|||||||
Reference in New Issue
Block a user