What better way to do this?
Doing nothing. ASP.NET MVC has a property HttpContext.Cache
that automatically caches for you. You just need to set the following in your common Controller :
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 on this settings table is frequent, cache is automatic.
Still, you can manually set cache :
HttpContext.Cache["MetaDescription"] = "Alguma descrição";