开发者

UserNamePasswordValidator and caching results

I have a UserNamePasswordValidator and it hits a database to verify that the request is valid for the wcfclientcredentials.

I came to realize that I don't want to hit the database everytime I make a call.

What is the best way to cache the results?

ie if I alr开发者_如何学运维eady know username/pass is valid why check it over and over again?


Although I agree with mellamokb's comment but if you really wana do it...

I would go for Dictionary<UserName, SecureString>

Plus you will have to make sure that you update the dictionary in case of password change


You could cache the username/password in a dictionary with username as the key and password as the value.

Dictionary<string, string> userName_Pwd_Cache = new Dictionary<string, string>();
//caching username/password code

    if(userName_Pwd_Cache.ContainsKey(userNameVar)) //let userNameVar is entered username
    {
           if(userName_Pwd_Cache[userNameVar] == passwordVar) //let passwordVar is entered passwords
           {
               //user authenticated
           }
           else
           {
               //authentication failed 
           }
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜