I have a List<string>
being stored in my cache with about 600K members. I want this to act as the backend for an ajaxAjax autocomplete box. It's accessible through my model:
public static List<string> GetProducts()
{
var cached = HttpContext.Current.Cache["MyApp-Products"];
if (cached == null)
{
UpdateCache();
return GetProducts();
}
return ((List<string>)cached);
}
My ajax call uses this method to get it's data:
[HttpPost]
public JsonResult ProductSearch(string term)
{
return Json(MyModel.GetProducts()
.Where(s => s.ToUpper().StartsWith(term.ToUpper()))
.OrderBy(s => s)
.Take(5)
.ToList<string>()
);
}
The problem is, this ajaxAjax call to ProductSearch()
is waiting 2.09 seconds for a response. I'm doing the same with other objects in my model that have smaller list sizes and they respond in 35-125ms (which is acceptable).
So, I believe my performaceperformance issue is somewhere in accessing the list. Is there a faster way to access this list besides the Linq code that I'm using, or just a better way to use Linq?
Thanks!