How to use ASP.NET Caching in Data Access Layer

Posted by Webmaster under ASP.NET on 4/30/2007 | Views : 9637 | Status : [Administrator] | Replies : 4
I have a separate DAL in my project. At one place i have list of some records and on each request i have to get that records, I am trying to Cache those records so in each susequent request i will get those reocrds from the Cache instead of going to database (in this way i will save database hit).

I tried to cache the DataView object as Cache["SpNames"] = RecordsView;
but at the time of compilation it giving error like The name 'Cache' does not exist in the class or namespace error.

I tried to use using System.Web.Caching; namespace but in DAL (class library its not working ( The type or namespace name 'Caching' does not exist in the lass or namespace 'System.Web' (are you missing an assembly reference?))

Any help will be appreciated.
Thanks

Best regards,
Webmaster
http://www.dotnetfunda.com



Responses

Posted by: Jeyanthi on: 7/25/2013 [Member] Starter | Points: 25

Up
0
Down
Add reference to System.Web.dll assembly and try the following

System.Web.HttpContext.Current.Cache["SomeVariableName"] = ObjectToCache;

Regards,
Jeyanthi

Webmaster, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Webmaster on: 6/11/2007 [Administrator] HonoraryPlatinum

Up
0
Down
Use

System.Web.HttpContext.Current.Cache["SomeVariableName"] = ObjectToCache;

Best regards,
Webmaster
http://www.dotnetfunda.com

Webmaster, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ramakrishnasri on: 11/14/2007 [Member] Starter

Up
0
Down
hai,

i had gone through problem. why don't u go for sessions instade of cache.
in sessions u can also pass the number of elements also.
so,why don't u go for sessions.


Webmaster, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Raja on: 11/14/2007 [Member] Starter

Up
0
Down
I think the scope of session is limited to the user instance, but here the records has to be available for any requeset from any user so Session will not work here.

Following code is the way to go

System.Web.HttpContext.Current.Cache["SomeVariableName"] = ObjectToCache;

Regards,
Raja, USA

Webmaster, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response