1

I have a ASP.Net 4.0 web application and I extract and put the data into the cache for 10 minutes by using the following code:

List<Student> students = new List<Student>();

if (System.Web.HttpRuntime.Cache["MyStudents"] != null)
{
    students = (List<students >)System.Web.HttpRuntime.Cache["MyStudents"];
    Response.Write("Get From Cache");
}
else
{
    students = MyClass.GetStudents();
    System.Web.HttpRuntime.Cache.Insert("MyStudents", students, null, DateTime.Now.AddMinutes(10), TimeSpan.Zero);
    Response.Write("Get From DB");
}

It works only for the single user or PC. If I use another pc to browse the same page, it connects to the database at the first load. But it uses the cache for the next time. The problem is that it's not sharing the cache object between different session.

Could you pls advise me where I am doing wrong? Thanks.

4

1 に答える 1