我有一个UserNamePasswordValidator,它命中一个数据库以验证该请求对于wcfclientcredentials有效。UserNamePasswordValidator和缓存结果
我意识到我不想在每次打电话时都敲击数据库。
什么是缓存结果的最佳方式?
即如果我已经知道用户名/密码是有效的,为什么一遍又一遍地检查它?
我有一个UserNamePasswordValidator,它命中一个数据库以验证该请求对于wcfclientcredentials有效。UserNamePasswordValidator和缓存结果
我意识到我不想在每次打电话时都敲击数据库。
什么是缓存结果的最佳方式?
即如果我已经知道用户名/密码是有效的,为什么一遍又一遍地检查它?
您可以将username/password
缓存为dictionary
,其中username
为密钥,password
为值。
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
}
}
虽然我mellamokb的评论表示赞同,但如果你真的瓦纳做...
我会去Dictionary<UserName, SecureString>
另外,你必须确保你更新字典的情况下,密码更改
应用程序是否因数据库命中而导致性能下降?如果没有,请不要修理没有损坏的东西。 – mellamokb 2011-05-13 19:06:21