Join us this Friday for AI in Action at the Virtual Happy Hour! This free virtual event is open to all—enroll now on Academy and don’t miss out.

 

Outputcache logged in customers

Vote:
 

Hi,

I just noticed that, when our customers log in on our homepage, the content is never cached. This makes sense for webeditors - but can I somehow also display cached content to logged in customers/users?

Br
Lasse

#183769
Oct 23, 2017 9:14
Vote:
 

Personalized content will be problematic. Access rights and filtered links as well. I would implement caching using object caching if you need it for logged in users. There are plenty of opportunities to shoot yourself in the foot though :)

#186341
Dec 18, 2017 10:49
Vote:
 

If you want to force caching on some page types, like articles or similar, where you know you won't have personalized content, you can use this attribute:

public class ForceContentOutputCacheAttribute : ContentOutputCacheAttribute
{
    public ForceContentOutputCacheAttribute()
    {
        this.UseOutputCacheValidator = (principal, context, duration) =>
        {
            if (duration != TimeSpan.Zero)
                return context.Request.HttpMethod.Equals("GET", StringComparison.OrdinalIgnoreCase);
            return false;
        };
    }
}

And on your controller:

[ForceContentOutputCache(Duration = 3600)]
public class ArticleController : PageController<ArticlePage>
{
}
#186458
Edited, Dec 19, 2017 21:17
Vote:
 

Hi,

Thank you very much for the inputs. 

Br

Lasse

#187439
Jan 23, 2018 9:53
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.