[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

microsoft.public.dotnet.framework.aspnet.caching

System.Web.Caching.Cahe doesn't work?Hi,

cheloman12

2/23/2006 1:30:00 PM

Hi,
I'm using System.Web.Caching.Cahe to mantain a datatable object in an
asp.net user control.
this is de code i'm using:

//In the load event call LoadData method

protected void Page_Load(object sender, EventArgs e)
{
LoadData();
this.DataBind();
}

//In LoadData brings a datatable from database and inserts it to the cache
object if it doesn't exist previously. Later it should by retrieved from the
cache object.

private void LoadData()
{
if (!this.Page.IsPostBack || Cache["Data"] == null)
{
Interfaz.Datos oInterfaz = new Interfaz.Datos();
dtData = oInterfaz.BringData(UserID);
Cache.Insert("Data", dtData, null,
System.Web.Caching.Cache.NoAbsoluteExpiration,
TimeSpan.FromMinutes(Session.Timeout));
}
else
{
dtData = (DataTable)Cache["Data"];
}
dvData = dtData.DefaultView;
gvData.DataSource = dvData;
}

The problem is that the second time the page executes, Cache["Data"]
contains null.

I use this concept of caching from asp.net 1.1 and it works fine.

Someone knows why cache loses its objects?

Best Regards
Marcelo

6 Answers

cheloman12

2/23/2006 3:27:00 PM

0

Hi Again,

I've forgot to say that the control is in an aspx page that work with a
master page.

I've just use the same code in an aspx page without the master page and the
cache runs ok.

is this a bug? because i haven't seen any KB about this behavior.

Best Regards

Marcelo

"cheloman12" wrote:

> Hi,
> I'm using System.Web.Caching.Cahe to mantain a datatable object in an
> asp.net user control.
> this is de code i'm using:
>
> //In the load event call LoadData method
>
> protected void Page_Load(object sender, EventArgs e)
> {
> LoadData();
> this.DataBind();
> }
>
> //In LoadData brings a datatable from database and inserts it to the cache
> object if it doesn't exist previously. Later it should by retrieved from the
> cache object.
>
> private void LoadData()
> {
> if (!this.Page.IsPostBack || Cache["Data"] == null)
> {
> Interfaz.Datos oInterfaz = new Interfaz.Datos();
> dtData = oInterfaz.BringData(UserID);
> Cache.Insert("Data", dtData, null,
> System.Web.Caching.Cache.NoAbsoluteExpiration,
> TimeSpan.FromMinutes(Session.Timeout));
> }
> else
> {
> dtData = (DataTable)Cache["Data"];
> }
> dvData = dtData.DefaultView;
> gvData.DataSource = dvData;
> }
>
> The problem is that the second time the page executes, Cache["Data"]
> contains null.
>
> I use this concept of caching from asp.net 1.1 and it works fine.
>
> Someone knows why cache loses its objects?
>
> Best Regards
> Marcelo
>

demi

2/24/2006 5:26:00 PM

0

I'm having a similar problem. To investigate, I added a callback method
to be called when the cache was removed and I wrote out the "Reason".
It was underused. It seems that in XP on my machine, if I'm running
other apps including VS2005, asp.net thinks the memory is low and it
free's up my cache item pretty much instantantly. I have 1GB of memory
so I'm not sure what exactly the problem it and the cache item is not
that big. If anyone knows how to fix this, I'd appreciate some advice.

cheloman12 wrote:
> Hi,
> I'm using System.Web.Caching.Cahe to mantain a datatable object in an
> asp.net user control.
> this is de code i'm using:
>
> //In the load event call LoadData method
>
> protected void Page_Load(object sender, EventArgs e)
> {
> LoadData();
> this.DataBind();
> }
>
> //In LoadData brings a datatable from database and inserts it to the cache
> object if it doesn't exist previously. Later it should by retrieved from the
> cache object.
>
> private void LoadData()
> {
> if (!this.Page.IsPostBack || Cache["Data"] == null)
> {
> Interfaz.Datos oInterfaz = new Interfaz.Datos();
> dtData = oInterfaz.BringData(UserID);
> Cache.Insert("Data", dtData, null,
> System.Web.Caching.Cache.NoAbsoluteExpiration,
> TimeSpan.FromMinutes(Session.Timeout));
> }
> else
> {
> dtData = (DataTable)Cache["Data"];
> }
> dvData = dtData.DefaultView;
> gvData.DataSource = dvData;
> }
>
> The problem is that the second time the page executes, Cache["Data"]
> contains null.
>
> I use this concept of caching from asp.net 1.1 and it works fine.
>
> Someone knows why cache loses its objects?
>
> Best Regards
> Marcelo

kevyou

2/28/2006 4:30:00 PM

0

i'm having the same problem in web services, the second call see's my cached objects removed. But interestingly I set test string to the Cache (="ttt")
and that stays 'live'
Changing to Application["cacheobject"]=object keeps the cache items alive as expected, so I assume something is desperately wrong with the Cache object.
In debug mode just before I access the Cache object for the secod time it is still in there, but when I do object o = (object) Cache["cacheobject"] it returns Null!!!

>I'm having a similar problem. To investigate, I added a callback method
> to be called when the cache was removed and I wrote out the "Reason".
> It was underused. It seems that in XP on my machine, if I'm running
> other apps including VS2005, asp.net thinks the memory is low and it
> free's up my cache item pretty much instantantly. I have 1GB of memory
> so I'm not sure what exactly the problem it and the cache item is not
> that big. If anyone knows how to fix this, I'd appreciate some advice.
>
> cheloman12 wrote:
> > Hi,
> > I'm using System.Web.Caching.Cahe to mantain a datatable object in an
> > asp.net user control.
> > this is de code i'm using:
> >
> > //In the load event call LoadData method
> >
> > protected void Page_Load(object sender, EventArgs e)
> > {
> > LoadData();
> > this.DataBind();
> > }
> >
> > //In LoadData brings a datatable from database and inserts it to the cache
> > object if it doesn't exist previously. Later it should by retrieved from the
> > cache object.
> >
> > private void LoadData()
> > {
> > if (!this.Page.IsPostBack || Cache["Data"] == null)
> > {
> > Interfaz.Datos oInterfaz = new Interfaz.Datos();
> > dtData = oInterfaz.BringData(UserID);
> > Cache.Insert("Data", dtData, null,
> > System.Web.Caching.Cache.NoAbsoluteExpiration,
> > TimeSpan.FromMinutes(Session.Timeout));
> > }
> > else
> > {
> > dtData = (DataTable)Cache["Data"];
> > }
> > dvData = dtData.DefaultView;
> > gvData.DataSource = dvData;
> > }
> >
> > The problem is that the second time the page executes, Cache["Data"]
> > contains null.
> >
> > I use this concept of caching from asp.net 1.1 and it works fine.
> >
> > Someone knows why cache loses its objects?
> >
> > Best Regards
> > Marcelo
>
>

___
Newsgroups brought to you courtesy of www.dotnetjohn.com

kevyou

2/28/2006 5:28:00 PM

0

definetly memory problems, my 1GB XP machine needed a reboot after my problems today figuring this out (2005 ide refused to start web service with problems attaching debugger).
All previous observations about cache entries dissapearing do not occur now.
Seems like the development environment is not keeping things 'clean'.

>i'm having the same problem in web services, the second call see's my cached objects removed. But interestingly I set test string to the Cache (="ttt")
> and that stays 'live'
> Changing to Application["cacheobject"]=object keeps the cache items alive as expected, so I assume something is desperately wrong with the Cache object.
> In debug mode just before I access the Cache object for the secod time it is still in there, but when I do object o = (object) Cache["cacheobject"] it returns Null!!!
>
> >I'm having a similar problem. To investigate, I added a callback method
> > to be called when the cache was removed and I wrote out the "Reason".
> > It was underused. It seems that in XP on my machine, if I'm running
> > other apps including VS2005, asp.net thinks the memory is low and it
> > free's up my cache item pretty much instantantly. I have 1GB of memory
> > so I'm not sure what exactly the problem it and the cache item is not
> > that big. If anyone knows how to fix this, I'd appreciate some advice.
> >
> > cheloman12 wrote:


___
Newsgroups brought to you courtesy of www.dotnetjohn.com

Manso

3/6/2006 9:04:00 PM

0

Did you manage to nail down the problem? Are you running development web
server or IIS? We're also experiencing problems where cache.insert doesn't
stick in the cache. Very frustrating.

Thanks,
Manso

"demi" wrote:

> I'm having a similar problem. To investigate, I added a callback method
> to be called when the cache was removed and I wrote out the "Reason".
> It was underused. It seems that in XP on my machine, if I'm running
> other apps including VS2005, asp.net thinks the memory is low and it
> free's up my cache item pretty much instantantly. I have 1GB of memory
> so I'm not sure what exactly the problem it and the cache item is not
> that big. If anyone knows how to fix this, I'd appreciate some advice.
>
> cheloman12 wrote:
> > Hi,
> > I'm using System.Web.Caching.Cahe to mantain a datatable object in an
> > asp.net user control.
> > this is de code i'm using:
> >
> > //In the load event call LoadData method
> >
> > protected void Page_Load(object sender, EventArgs e)
> > {
> > LoadData();
> > this.DataBind();
> > }
> >
> > //In LoadData brings a datatable from database and inserts it to the cache
> > object if it doesn't exist previously. Later it should by retrieved from the
> > cache object.
> >
> > private void LoadData()
> > {
> > if (!this.Page.IsPostBack || Cache["Data"] == null)
> > {
> > Interfaz.Datos oInterfaz = new Interfaz.Datos();
> > dtData = oInterfaz.BringData(UserID);
> > Cache.Insert("Data", dtData, null,
> > System.Web.Caching.Cache.NoAbsoluteExpiration,
> > TimeSpan.FromMinutes(Session.Timeout));
> > }
> > else
> > {
> > dtData = (DataTable)Cache["Data"];
> > }
> > dvData = dtData.DefaultView;
> > gvData.DataSource = dvData;
> > }
> >
> > The problem is that the second time the page executes, Cache["Data"]
> > contains null.
> >
> > I use this concept of caching from asp.net 1.1 and it works fine.
> >
> > Someone knows why cache loses its objects?
> >
> > Best Regards
> > Marcelo
>
>

Manso

3/6/2006 10:00:00 PM

0

Please see:

http://msdn.microsoft.com/newsgroups/managed/default.aspx?dg=microsoft.public.dotnet.framework.aspnet.caching&mid=10dc1581-5283-4693-b5e1-9b271927233e&...

"cheloman12" wrote:

> Hi,
> I'm using System.Web.Caching.Cahe to mantain a datatable object in an
> asp.net user control.
> this is de code i'm using:
>
> //In the load event call LoadData method
>
> protected void Page_Load(object sender, EventArgs e)
> {
> LoadData();
> this.DataBind();
> }
>
> //In LoadData brings a datatable from database and inserts it to the cache
> object if it doesn't exist previously. Later it should by retrieved from the
> cache object.
>
> private void LoadData()
> {
> if (!this.Page.IsPostBack || Cache["Data"] == null)
> {
> Interfaz.Datos oInterfaz = new Interfaz.Datos();
> dtData = oInterfaz.BringData(UserID);
> Cache.Insert("Data", dtData, null,
> System.Web.Caching.Cache.NoAbsoluteExpiration,
> TimeSpan.FromMinutes(Session.Timeout));
> }
> else
> {
> dtData = (DataTable)Cache["Data"];
> }
> dvData = dtData.DefaultView;
> gvData.DataSource = dvData;
> }
>
> The problem is that the second time the page executes, Cache["Data"]
> contains null.
>
> I use this concept of caching from asp.net 1.1 and it works fine.
>
> Someone knows why cache loses its objects?
>
> Best Regards
> Marcelo
>