What’s the best way to do it?
Doing nothing. ASP.NET MVC has a property HttpContext.Cache
that caches automatically for you. You just need to set the following in your Controller common:
public class Controller : System.Web.Mvc.Controller
{
protected readonly SeuProjetoContext context = new SeuProjetoContext();
protected override void Initialize(RequestContext requestContext)
{
base.Initialize(requestContext);
var configuracao = context.Configuracoes.FirstOrDefault();
ViewBag.MetaDescription = configuracao.MetaDescription;
ViewBag.MetaKeywords = configuracao.MetaDescription;
ViewBag.Title = // defina Title aqui
}
}
As the load of this configuration table is frequent, the cache is automatic.
Still, you can define the cache manually:
HttpContext.Cache["MetaDescription"] = "Alguma descrição";
Wouldn’t it be better to make this data available in a Source in the application? Understand that this data is usually not changed frequently and are only system parameters.
– Vinicius Grund