检索只是一次为当前的用户配置文件数据 [英] Is profile data for current user retrieved just once

查看:138
本文介绍了检索只是一次为当前的用户配置文件数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

结果

a)当当前用户访问的第一次资料目的,的确Asp.Net
获取该用户的完整个人资料或者配置文件属性检索的一个的时候,因为他们叫什么名字?

a) When current user accesses Profile object for the first time, does Asp.Net retrieve a complete profile for that user or are profile properties retrieved one at the time as they are called?

结果

b)在任何情况下,是对来自DB每次被调用或者是它检索时检索当前用户简档数据只是一次,然后保存为当前请求的持续时间

b) In any case, is profile data for current user retrieved from DB each time it is called or is it retrieved just once and then saved for the duration of current request?

结果

感谢名单

推荐答案

如果您想要保存数据库调用,您可以使用一个实用的方法来缓存的配置文件,也可以实现它处理缓存自己的自定义的MembershipProvider。

If you want to save a database call, you can use a utility method to cache the profile or you can implement your own custom MembershipProvider which handles the caching.

该实用程序的方法可能是在这种情况下,最简单的办法,除非你有其他的功能,要实现这将通过实现自定义的MembershipProvider送达。

The utility method is probably the simplest solution in this case unless you have other functionality you want to implement which would be served by implementing a custom MembershipProvider.

您可以参考以下链接了解详情:
<一href=\"http://stackoverflow.com/questions/146896/how-to-access-userid-in-asp-net-membership-without-using-membership-getuser\">http://stackoverflow.com/questions/146896/how-to-access-userid-in-asp-net-membership-without-using-membership-getuser

You can refer to this link for more details: http://stackoverflow.com/questions/146896/how-to-access-userid-in-asp-net-membership-without-using-membership-getuser

下面是一个实用的方法来做缓存的例子。你可以通过一个slidingMinutesToExpire,使其从缓存中的时间,以避免耗费过多的服务器内存,如果你有很多用户一定时间后过期。

Here's an example of a utility method to do caching. You can pass a slidingMinutesToExpire to make it expire from the cache after some duration of time to avoid consuming excess server memory if you have many users.

public static void AddToCache(string key, Object value, int slidingMinutesToExpire)
{
    if (slidingMinutesToExpire == 0)
    {
        HttpRuntime.Cache.Insert(key, value, null, System.Web.Caching.Cache.NoAbsoluteExpiration, System.Web.Caching.Cache.NoSlidingExpiration, System.Web.Caching.CacheItemPriority.NotRemovable, null);
    }
    else
    {
        HttpRuntime.Cache.Insert(key, value, null, System.Web.Caching.Cache.NoAbsoluteExpiration, TimeSpan.FromMinutes(slidingMinutesToExpire), System.Web.Caching.CacheItemPriority.NotRemovable, null);
    }
}

这篇关于检索只是一次为当前的用户配置文件数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆