[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

SMG

5/5/2005 6:46:00 AM


Hi All,
I have written a function which gives me dataset either from database or
from cache.

1. First time when the page is hitted there is no cachekeyname in cache so
it fires a query to database and insert the object into cache.
2. With the second hit it should pick up the data from cache as per the code
but still it picks up the data from database once again it insert a object
in cache

Is there any problem with the code,

Regards,
Shailesh

public DataSet GetCachedData(string CacheKeyName, DateTime ExpiryTime,string
SQLQueryorSP,CommandType cmdType,params SqlParameter[] commandParameters)
{
DataSet dsCached = null;
if(HttpContext.Current.Cache[CacheKeyName]!=null)
{
dsCached = (DataSet)HttpContext.Current.Cache[CacheKeyName];
//System.Web.HttpContext.Current.Response.Write("Comming data frm cache"
+ HttpContext.Current.Cache[CacheKeyName] + "<BR>");
}
else
{
if(cmdType == CommandType.StoredProcedure)
{
dsCached = SqlHelper.ExecuteDataset(SqlHelper.SqlConnectionString(),
CommandType.StoredProcedure, SQLQueryorSP, commandParameters);
}
else
{
dsCached = SqlHelper.ExecuteDataset(SqlHelper.SqlConnectionString(),
CommandType.Text, SQLQueryorSP, commandParameters);
}
// Inserting the data into Cache
HttpContext.Current.Cache.Insert(CacheKeyName, dsCached , null,
ExpiryTime, TimeSpan.Zero);
//System.Web.HttpContext.Current.Response.Write("Inserted into cache KEY
: " + CacheKeyName + "<BR>");
}
return dsCached;
}


4 Answers

Brock Allen

5/5/2005 1:29:00 PM

0

> Is there any problem with the code,

Are you having problems with this code?

-Brock
DevelopMentor
http://staff.develop....



SMG

5/6/2005 10:59:00 AM

0


it always insert the record in cache and does not pick the object from cache
Shailesh

"Brock Allen" <ballen@NOSPAMdevelop.com> wrote in message news:649620632508821129846560@msnews.microsoft.com...
> Is there any problem with the code,

Are you having problems with this code?

-Brock
DevelopMentor
http://staff.develop....


Brock Allen

5/6/2005 4:54:00 PM

0

> it always insert the record in cache and does not pick the object from

Well, looking at it, it seems fine. The Cache can get purged when the app
restarts, which can happen for several reasons, including web.config being
modified. I suspect that''s not your problem though... Any more info would
help.

-Brock
DevelopMentor
http://staff.develop....




SMG

5/7/2005 11:21:00 AM

0

yes I figured it out, the problem was it was taking some junk date i.e. 01
01 0001 something like this... I don''t know what went wrong, I changed the
expiry date and tried it is working.

Thanks to all.

"Brock Allen" <ballen@NOSPAMdevelop.com> wrote in message
news:665246632509808465425232@msnews.microsoft.com...
> it always insert the record in cache and does not pick the object from

Well, looking at it, it seems fine. The Cache can get purged when the app
restarts, which can happen for several reasons, including web.config being
modified. I suspect that''s not your problem though... Any more info would
help.

-Brock
DevelopMentor
http://staff.develop....