C # MVC5 - Using OutputCache

1

I recently started to study OutputCache and its uses, due to its use in a corporate system.

I'm using OutputCache to load all the menus a user (logged in) will have access to. However, I want every login to reload this method again, regardless of whether the duration has expired or not ...

Does anyone know if I can do this via override GetVaryByCustomString no Global.asax ? If so, how?

Hugs!

    
asked by anonymous 08.07.2015 / 17:08

1 answer

0

I do not quite understand how you're using OutputCache on Global.asax . Normally a decoration is Attribute in Controller . In your case, it would be in Action login:

    [OutputCache(Duration=int.MaxValue, VaryByParam="none")]
    public ActionResult Login()
    {
        /* Passos do seu método de login aqui */
    }

Or, you can use an Action to mount the menu and put the OutputCache setting on it. Teach this in this answer :

    [ChildActionOnly]
    [OutputCache(Duration=int.MaxValue, VaryByParam="none")]
    public ActionResult Menu()
    {
        /* Monte seu menu aqui */
    }

EDIT

I understood the doubt. In this case, I think it would be nice for you to force the cache to expire in Logout :

public ActionResult Logout()
{
    var url = Url.Action("ControllerDeLogin", "Login");
    HttpResponse.RemoveOutputCacheItem(url);
    // Coloque o restante da lógica aqui.
}
    
08.07.2015 / 17:24