2
I’ve been reading the article: http://www.asp.net/mvc/overview/older-versions-1/controllers-and-routing/improving-performance-with-output-caching-cs
And I started using the:
[OutputCache(Duration = 60, VaryByParam = "none")]
When I put it on the controller, I can clearly tell the difference.
But when I’m using it in a library that’s called by mine controller, it seems that the cache does not happen.
The code is as follows::
[OutputCache(Duration = 60, Location = OutputCacheLocation.ServerAndClient, VaryByParam = "none")]
internal IEnumerable<CPUStats> ProcessarStatsSQL()
{
var DateQuery = db.servidorSQL.ToList().Select(o => new CPUStats
{
Data = DateTime.Parse(o.Data, new CultureInfo("en-US")),
CPU = Double.Parse(o.CPU,new CultureInfo("en-US")),
RAM = Double.Parse(o.RAM, new CultureInfo("en-US")),
Disco = Double.Parse(o.Disco, new CultureInfo("en-US"))
});
return DateQuery;
}
[OutputCache(Duration = 60, VaryByParam = "none")]
public DateTime Data_SQL()
{
var DateQuery = ProcessarStatsSQL();
var Data = DateQuery.OrderByDescending(x => x.Data).Take(1).ToList();
return (DateTime)Data.FirstOrDefault().Data;
}
[OutputCache(Duration = 60, VaryByParam = "none")]
public Double IO_SQL()
{
var DateQuery = ProcessarStatsSQL();
var IO = DateQuery.OrderByDescending(x => x.Data).Take(5).ToList();
return (double)IO.Average(a => a.Disco);
}
Namely the IO_SQL()
and Data_SQL()
should not use the cache previously made?
But in debug I see that it processes the query in Database for each IO_SQL()
and Data_SQL()
I can use in an Htmlhelper?
[OutputCache(Duration = 60, VaryByParam = "none")]
public static IHtmlString VerificaRAM(this HtmlHelper helper)
Have you ever taken the test using a
Duration
longer and no debug? Debug forces the expiration of cache.– Leonel Sanches da Silva
already...cacheoutput does not work in a class outside the controller
– Dorathoto