I have a big site that needs to call Membership.GetUser() plenty of times. So, what I thought is to push MembershipUser in Cache for 10 seconds and get it when need meanwhile. And I wrote code like this
public static MembershipUser GetCurrentUser()
{
System.Security.Principal.IIdentity identity = HttpContext.Current.User.Identity;
if (identity.IsAuthenticated)
{
string key = "User_" + identity.Name;
MembershipUser tuser;
if (HttpRuntime.Cache[key] != null)
tuser = (MembershipUser)HttpRuntime.Cache[key];
else
{
tuser = Membership.GetUser(identity.Name);
if (tuser != null)
{
HttpRuntime.Cache.Add(key, tuser,
null,
DateTime.UtcNow.AddSeconds(10),
...
Go to the complete details ...