473,785 Members | 3,142 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Cache items missing

Hi,

I am persisting the viewstate for each page into the Cache object, below is
shown my methods for saving and loading:

I am able to save the viewstate to the cache and most times I can load it
ok, however it seems that every now and again it fails to Deserialize the
viewstate.

My Application pool is set to shutdown after 180mins of idle.

IIS6.0 W2K3 SVR
TIA

MattC

private string ViewStateCacheK ey
{
get{ return "VIEWSTATE_ " + Request.UserHos tAddress; }
}

protected override void SavePageStateTo PersistenceMedi um(object viewState)
{
LosFormatter oLosFormatter = new LosFormatter();
StringWriter oStringWriter = new StringWriter();
oLosFormatter.S erialize(oStrin gWriter, viewState);
string str = this.ViewStateC acheKey + "_" + Guid.NewGuid(). ToString();

try
{
Cache.Insert(st r, //key
oStringWriter.T oString(), //value
null, //dependency
Cache.NoAbsolut eExpiration, //no absolute expiration
new TimeSpan(0,0,Se ssion.Timeout + 10,0,0), //sliding expiration
Seesion timeout
CacheItemPriori ty.High,
onRemove); //call back on removal
}
catch(Exception e)
{
throw new Exception("Fail ed to store viewstate in Cache", e);
}

}

RegisterHiddenF ield("__VIEWSTA TE_KEY", str);
RegisterHiddenF ield("__VIEWSTA TE", String.Empty);

}

protected override object LoadPageStateFr omPersistenceMe dium()
{

object viewstate = null;//return viewstate
LosFormatter oLosFormatter = new LosFormatter();
string str = Request.Form["__VIEWSTATE_KE Y"];

try
{
viewstate = oLosFormatter.D eserialize(Cach e[str].ToString());//cache
}
catch(Exception e)
{
Events.WriteToL og("Failed to deserialize ViewState '" + str +"'
from cache: " + e.Message);//system event log
}

return viewstate;

}
Nov 19 '05 #1
3 1944
At the 180 minute mark, the pool is recycled and the app domain is unloaded.
Variables and objects belonging to that application domain are lost. Your
viewstate may still be there, but the cache values are gone.

--
Regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
The Microsoft Office Web Components Black Book with .NET
Now Available @ http://www.lulu.com/owc
----------------------------------------------------------
"MattC" <m@m.com> wrote in message
news:%2******** ********@TK2MSF TNGP14.phx.gbl. ..
Hi,

I am persisting the viewstate for each page into the Cache object, below
is shown my methods for saving and loading:

I am able to save the viewstate to the cache and most times I can load it
ok, however it seems that every now and again it fails to Deserialize the
viewstate.

My Application pool is set to shutdown after 180mins of idle.

IIS6.0 W2K3 SVR
TIA

MattC

private string ViewStateCacheK ey
{
get{ return "VIEWSTATE_ " + Request.UserHos tAddress; }
}

protected override void SavePageStateTo PersistenceMedi um(object viewState)
{
LosFormatter oLosFormatter = new LosFormatter();
StringWriter oStringWriter = new StringWriter();
oLosFormatter.S erialize(oStrin gWriter, viewState);
string str = this.ViewStateC acheKey + "_" + Guid.NewGuid(). ToString();

try
{
Cache.Insert(st r, //key
oStringWriter.T oString(), //value
null, //dependency
Cache.NoAbsolut eExpiration, //no absolute expiration
new TimeSpan(0,0,Se ssion.Timeout + 10,0,0), //sliding expiration
Seesion timeout
CacheItemPriori ty.High,
onRemove); //call back on removal
}
catch(Exception e)
{
throw new Exception("Fail ed to store viewstate in Cache", e);
}

}

RegisterHiddenF ield("__VIEWSTA TE_KEY", str);
RegisterHiddenF ield("__VIEWSTA TE", String.Empty);

}

protected override object LoadPageStateFr omPersistenceMe dium()
{

object viewstate = null;//return viewstate
LosFormatter oLosFormatter = new LosFormatter();
string str = Request.Form["__VIEWSTATE_KE Y"];

try
{
viewstate = oLosFormatter.D eserialize(Cach e[str].ToString());//cache
}
catch(Exception e)
{
Events.WriteToL og("Failed to deserialize ViewState '" + str +"'
from cache: " + e.Message);//system event log
}

return viewstate;

}

Nov 19 '05 #2
Also, UserHostAddress isn't guaranteed to be unique per visitor...namel y
those who sit behind a proxy (increasingly popular). I would expect strange
behaviour if two users from behind the same proxy visit your application.
This is likely why sessions are prefered for server-side viewstate than
cache.

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Alvin Bruney [MVP]" <vapor at steaming post office> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
At the 180 minute mark, the pool is recycled and the app domain is unloaded. Variables and objects belonging to that application domain are lost. Your
viewstate may still be there, but the cache values are gone.

--
Regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
The Microsoft Office Web Components Black Book with .NET
Now Available @ http://www.lulu.com/owc
----------------------------------------------------------
"MattC" <m@m.com> wrote in message
news:%2******** ********@TK2MSF TNGP14.phx.gbl. ..
Hi,

I am persisting the viewstate for each page into the Cache object, below
is shown my methods for saving and loading:

I am able to save the viewstate to the cache and most times I can load it ok, however it seems that every now and again it fails to Deserialize the viewstate.

My Application pool is set to shutdown after 180mins of idle.

IIS6.0 W2K3 SVR
TIA

MattC

private string ViewStateCacheK ey
{
get{ return "VIEWSTATE_ " + Request.UserHos tAddress; }
}

protected override void SavePageStateTo PersistenceMedi um(object viewState) {
LosFormatter oLosFormatter = new LosFormatter();
StringWriter oStringWriter = new StringWriter();
oLosFormatter.S erialize(oStrin gWriter, viewState);
string str = this.ViewStateC acheKey + "_" + Guid.NewGuid(). ToString();

try
{
Cache.Insert(st r, //key
oStringWriter.T oString(), //value
null, //dependency
Cache.NoAbsolut eExpiration, //no absolute expiration
new TimeSpan(0,0,Se ssion.Timeout + 10,0,0), //sliding expiration
Seesion timeout
CacheItemPriori ty.High,
onRemove); //call back on removal
}
catch(Exception e)
{
throw new Exception("Fail ed to store viewstate in Cache", e);
}

}

RegisterHiddenF ield("__VIEWSTA TE_KEY", str);
RegisterHiddenF ield("__VIEWSTA TE", String.Empty);

}

protected override object LoadPageStateFr omPersistenceMe dium()
{

object viewstate = null;//return viewstate
LosFormatter oLosFormatter = new LosFormatter();
string str = Request.Form["__VIEWSTATE_KE Y"];

try
{
viewstate = oLosFormatter.D eserialize(Cach e[str].ToString());//cache }
catch(Exception e)
{
Events.WriteToL og("Failed to deserialize ViewState '" + str +"' from cache: " + e.Message);//system event log
}

return viewstate;

}


Nov 19 '05 #3
Guys,

The viewstate not being found is happening at times well within the 180min
mark. The proxy point is well taken and may be something to consider,
however, this is an Intranet app and so does not suffer with this.

I think I have found my answer. It lies in the priority I gave the cache
items.
CacheItemPriori ty.High

I think as the worker process grew with all the postbacks storing new
viewstate ASP.NET removed some entries to free resources.

As a test I have set this to NotRemovable and am relying on the expiration
to remove it.

MattC
"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:ui******** *****@TK2MSFTNG P15.phx.gbl...
Also, UserHostAddress isn't guaranteed to be unique per visitor...namel y
those who sit behind a proxy (increasingly popular). I would expect
strange
behaviour if two users from behind the same proxy visit your application.
This is likely why sessions are prefered for server-side viewstate than
cache.

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Alvin Bruney [MVP]" <vapor at steaming post office> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
At the 180 minute mark, the pool is recycled and the app domain is

unloaded.
Variables and objects belonging to that application domain are lost. Your
viewstate may still be there, but the cache values are gone.

--
Regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
The Microsoft Office Web Components Black Book with .NET
Now Available @ http://www.lulu.com/owc
----------------------------------------------------------
"MattC" <m@m.com> wrote in message
news:%2******** ********@TK2MSF TNGP14.phx.gbl. ..
> Hi,
>
> I am persisting the viewstate for each page into the Cache object,
> below
> is shown my methods for saving and loading:
>
> I am able to save the viewstate to the cache and most times I can load it > ok, however it seems that every now and again it fails to Deserialize the > viewstate.
>
> My Application pool is set to shutdown after 180mins of idle.
>
> IIS6.0 W2K3 SVR
>
>
> TIA
>
> MattC
>
> private string ViewStateCacheK ey
> {
> get{ return "VIEWSTATE_ " + Request.UserHos tAddress; }
> }
>
> protected override void SavePageStateTo PersistenceMedi um(object viewState) > {
> LosFormatter oLosFormatter = new LosFormatter();
> StringWriter oStringWriter = new StringWriter();
> oLosFormatter.S erialize(oStrin gWriter, viewState);
> string str = this.ViewStateC acheKey + "_" + Guid.NewGuid(). ToString();
>
> try
> {
> Cache.Insert(st r, //key
> oStringWriter.T oString(), //value
> null, //dependency
> Cache.NoAbsolut eExpiration, //no absolute expiration
> new TimeSpan(0,0,Se ssion.Timeout + 10,0,0), //sliding expiration
> Seesion timeout
> CacheItemPriori ty.High,
> onRemove); //call back on removal
> }
> catch(Exception e)
> {
> throw new Exception("Fail ed to store viewstate in Cache", e);
> }
>
> }
>
> RegisterHiddenF ield("__VIEWSTA TE_KEY", str);
> RegisterHiddenF ield("__VIEWSTA TE", String.Empty);
>
> }
>
> protected override object LoadPageStateFr omPersistenceMe dium()
> {
>
> object viewstate = null;//return viewstate
> LosFormatter oLosFormatter = new LosFormatter();
> string str = Request.Form["__VIEWSTATE_KE Y"];
>
> try
> {
> viewstate = oLosFormatter.D eserialize(Cach e[str].ToString());//cache > }
> catch(Exception e)
> {
> Events.WriteToL og("Failed to deserialize ViewState '" + str +"' > from cache: " + e.Message);//system event log
> }
>
> return viewstate;
>
> }
>



Nov 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
2670
by: Bill H | last post by:
I have a routine that displays 60 items (with thumbnails) per page. You can click any item and displays a new page with item details. When the user back pages it runs the query again to display all the items. Is there a way to cache that page and images so that second query doesn't execute? I do offer a pop-up window using Java but is not the default and not used by many. I'd really like to get rid of that second query. ;) TIA
4
2469
by: Angel | last post by:
I am saving items in the cache in my code behind. By setting these items with an expiration are these items only available for the page its being set or throughout the application? My next question is can these cache items be accessed on the client side code(Javascript), If so, how? do you have any javascript code out there that accesses these cached items from the code behind? thank you in advance...
4
4178
by: Guadala Harry | last post by:
I want to create a STATIC method that removes all items from the Cache. Questions: 1. Is a safe thing to do (any threading issues?) 2. Is the following code a good way to get the job done - given that there is apparently no method like Cache.Clear() or Cache.Items.Clear()? Or am I missing an easier way to do it? string currentKey= "";
1
1420
by: Christopher | last post by:
In one of our ASP.NET Pages, we are starting a new background thread that we do not need to go and get any status on or use after the page finishes. The thread merely does some background stuff on its own and finishes on its own, no feedback back to the user (by design). Within that thread however, some items need to be accessed and/or inserted into the Cache for possible subsequent processing by another page. Many examples I see of...
1
1285
by: W. Jordan | last post by:
Hello, I would like to instantiate multiple Cache instances within my web application, for instance, one for database related items, one for application configuration items, one for user preferences items, and etc. Is it ok to instatiate multiple Cache instances by calling the constructor method of Cache
6
1768
by: Adam | last post by:
On an xp machine, the caching works as expected. I have deployed to a win2k server, and an item I add to the cache expires almost immediately some times and in under a minute in other times. The aspnet_wp process is not restarting during this time, and there are no other requests, so nothing should be clearing this out. I have added a CacheItemRemovedCallback which writes debug info out to a DefaultTraceListener, but no output shows up on...
5
2121
by: Stan SR | last post by:
Hi, Some newbie questions.. :-) First, what is the namespace to use for the Cache class ? When I use this bit of code I get an error if (Cache==null) Cache.Insert("myUserList",userlist); I don't know which namespace to use.
3
3063
by: poolieweb | last post by:
I have created a custom user control which creates a ASPxMenu ( Same fucntion as standard menu control) from data retreved from a webservice (Reporting Services) which deals with user access. This process is slow. And as the menu object will not change in a session I am trying to cache the menu with the session user as the key. The problem is that I can not retreve the menu object after the first request. The menu items are resident in the...
1
1248
by: BizWorld | last post by:
I am trying to cache a full DROP Down that can have lot of values. so i have 500 site users hitting a page in a second. i need to cache some controls that does not change quite often during the day. i am trying to test HTTRuntime.Cache object. in debug mode i can see the values on server side after i get the drop down from the cache but some how it does not show the values on generated html page. any idea what i am missing??? If...
0
9645
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10327
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10151
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8973
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7499
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5381
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4053
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3647
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.