improve cache

This commit is contained in:
Tommy Parnell
2015-10-10 15:50:16 -04:00
parent 8938f8d668
commit 92505eb5bb
7 changed files with 17 additions and 20 deletions

View File

@@ -9,15 +9,17 @@ using DotNetMashup.Web.Global;
using DotNetMashup.Web.Model;
using DotNetMashup.Web.ViewModel;
using Microsoft.AspNet.Mvc;
using Microsoft.Framework.Caching.Memory;
namespace DotNetMashup.Web.Controllers
{
public class HomeController : Controller
{
private readonly IMemoryCache cache;
private readonly ISiteSetting setting;
private readonly Factory.RepositoryFactory factory;
public HomeController(Factory.RepositoryFactory factory, ISiteSetting setting)
public HomeController(Factory.RepositoryFactory factory, ISiteSetting setting, IMemoryCache cache)
{
if(factory == null)
{
@@ -29,9 +31,9 @@ namespace DotNetMashup.Web.Controllers
}
this.factory = factory;
this.setting = setting;
this.cache = cache;
}
[ResponseCache(Duration = 3600, NoStore = true, Location = ResponseCacheLocation.Any)]
public async Task<IActionResult> Index(int page = 1)
{
var factoryData = (await factory.GetData());

View File

@@ -17,7 +17,7 @@ namespace DotNetMashup.Web.Extensions
Title = new TextSyndicationContent(settings.Title),
Id = "DotNet Mashup",
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)
.Distinct()
@@ -25,7 +25,7 @@ namespace DotNetMashup.Web.Extensions
authors.ForEach(a => feed.Authors.Add(a));
authors.ForEach(a => feed.Contributors.Add(a));
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;
}

View File

@@ -15,6 +15,7 @@ namespace DotNetMashup.Web.Extensions
{
PublishedDate = tweet.CreatedAt,
Content = tweet.Text,
OriginalLink = new Uri($"https://twitter.com/statuses/{tweet.Id}"),
tweet = new Lazy<Task<IOEmbedTweet>>(() => tweet.GenerateOEmbedTweetAsync()),
Author = new Author
{

View File

@@ -38,8 +38,8 @@
var loading = false;
$(window).on('scroll', function () {
var loadingImage = $('.loadWheel');
var tile = $('.tile').last();
if($(window).scrollTop() + tile.height() + 150 >= tile.position().top && !loading ) {
var tile = $('.tileRow').last();
if($(window).scrollTop() + tile.height() + 250 >= tile.position().top && !loading ) {
loading = true
loadingImage.show();
$.ajax('/Home/Tiles', {data:{page:page+1}})
@@ -50,7 +50,7 @@
var resd = $(data);
resd.find('img').addClass('img-responsive');
$('#tilesContainer').append(resd).find('.tile').addClass('show');
})
.error(function(){
loadingImage.hide();
@@ -58,8 +58,6 @@
}
});
});
</script>
}

View File

@@ -1,9 +1,4 @@
@model DotNetMashup.Web.Model.TwitterData
<cache vary-by="@Model.GetHashCode()">
<div class="row">
<div class="col-md-offset-3">
@Html.Raw((await Model.tweet.Value)?.HTML)
</div>
</div>
</cache>
<div class="col-md-offset-3">
@Html.Raw((await Model.tweet.Value)?.HTML)
</div>

View File

@@ -1,3 +1,4 @@
@model DotNetMashup.Web.Model.IExternalData
@Html.DisplayFor(a => a)
<cache vary-by="@Model.GetHashCode()">
@Html.DisplayFor(a => a)
</cache>

View File

@@ -21,7 +21,7 @@
<footer>
<p>&copy; 2015 - DotNetMashup.Web</p>
</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"
asp-fallback-src="~/lib/jquery/dist/jquery.min.js"
asp-fallback-test="window.jQuery">