i have i page where i use autocomplete jquery plugin. this might filter from database. but i do not want to make request to DB. so i have write it to session object as List. and every time i am filtering data from this session. what i am doing wrong or have there any other way to do it?
1 Answer
I would recommend you using the Cache object instead of the Session. Remember that the session is tied to a particular user. So if another user comes to your site he will hit the database as well. The Cache object is common for all users. So your controller action might look something like this:
public ActionResult Foo(string q)
{
var data = HttpContext.Cache[q];
if (data == null)
{
data = FetchFromDb(q);
HttpContext.Cache[q] = data;
}
return Json(data, JsonRequestBehavior.AllowGet);
}
3 Comments
AEMLoviji
has there any limit in Cache. can i write 10000 rows to cache?
Darin Dimitrov
@AEMLoviji, this will depend on where did you configure the cache to be stored. By default it is stored in memory, so the limit is the available memory. But you could distribute it by using providers.
AEMLoviji
i understand you. it is stored in server memory as session object by default.