public static IEnumerable<Student> GetStudents()
{
List<Student> students = (List<Student>)HttpContext.Current.Cache.Get("GetAllStudentWithImg");
if (students!= null)
{
return students ;
}
students = new List<Student>();
using (PrincipalContext context = GetPrincipalContext())
{
using (UserPrincipal uprinc = new UserPrincipal(context))
{
using (PrincipalSearcher psearcher = new PrincipalSearcher(uprinc))
{
students = psearcher.FindAll()
.Select(x => new Student((DirectoryEntry)x.GetUnderlyingObject()))
.ToList();
}
}
}
HttpContext.Current.Cache.Add("GetAllStudentWithImg", students, null,
DateTime.UtcNow.AddMinutes(60),
System.Web.Caching.Cache.NoSlidingExpiration,
System.Web.Caching.CacheItemPriority.Normal, null);
return students;
}
I created this function to get values from my database and it work but it load slowly, the pictures are not that many or big, so its not the content, I wonder if someone want to help me with improving my code?