我有一个查询,它正在向AD发送并抓取所有电子邮件。我的问题是,查询需要花费很长时间才能执行(通过 var whatEverString = "My test String";
var pattern = /^my/i
var result = pattern.test(whatEverString);
if (result === true) {
console.log(pattern, "pattern did match !");
} else {
console.log(pattern, " pattern did NOT match");
}
15-20秒)来提取大约3,000个电子邮件地址。我正在考虑在AJAX
中存储结果集(在列表中)。我将列表放入下拉列表中以填充电子邮件。这是我的疑问:
memory cache
所以我的困境是,我正试图找到一种方法来加快下载列表的下载过程。实现这一目标的最佳方法是什么?内存缓存?我愿意接受你认为合理的任何选择......
答案 0 :(得分:1)
https://msdn.microsoft.com/en-us/library/94xkskdf.aspx将其存储在应用程序中。每次回收应用程序池时都会清理它,并在其余时间保持不变。这个工作没什么特别的。
[WebMethod]
public static List<EmailDetails> GetEmails()
{
if(HttpContext.Current.Application["sortedEmailAddresses"]==null) {
List<EmailDetails> emailAddresses = new List<EmailDetails>();
//queries AD to pull all users
var search = new DirectorySearcher();
search.Filter = "(&(objectClass=user)(mail=*)(displayName=*))";
search.PageSize = 1000;
using (var results = search.FindAll())
{
foreach (SearchResult result in results)
{
emailAddresses.Add(new EmailDetails
{
EmailAddress = result.Properties["mail"][0].ToString(),
EmailDisplayName = result.Properties["displayName"][0].ToString()
});
}
}
//sort email address list alphabetically and return sorted list
List<EmailDetails> sortedEmailAddresses = emailAddresses.OrderBy(o => o.EmailDisplayName).ToList();
HttpContext.Current.Application["sortedEmailAddresses"] = sortedEmailAddresses;
}
return HttpContext.Current.Application["sortedEmailAddresses"] as List<EmailDetails>;
}