473,785 Members | 2,335 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

problem with items disappearing for cache

Hi Everybody,

I'm trying to save some items in the asp.net cache, but they are removed
from the cache WAY before they are supposed to (at least as I understand the
documentation).

I add the object to the cache using

this.Context.Ca che.Insert(key, userInfo, null,
System.Web.Cach ing.Cache.NoAbs oluteExpiration , TimeSpan.FromMi nutes(10),
System.Web.Cach ing.CacheItemPr iority.Default,
new System.Web.Cach ing.CacheItemRe movedCallback(i temRemoved));

but the Item is removed from the cache (with reason of underused) after
something like 1 minute.

What is going on here?

Thanks,
Nadav
Feb 13 '07 #1
10 4346
Is the system under memory pressure?

Is the worker process being recycled?

There are performance counters to help identify both problems above, in
addition to specific performance counters that track the behaviour of the
Cache API.

Karl
--
http://www.openmymind.net/
http://www.fuelindustries.com/
"Nadav Popplewell" <Ba********@new sgroup.nospamwr ote in message
news:15******** *************** ***********@mic rosoft.com...
Hi Everybody,

I'm trying to save some items in the asp.net cache, but they are removed
from the cache WAY before they are supposed to (at least as I understand
the
documentation).

I add the object to the cache using

this.Context.Ca che.Insert(key, userInfo, null,
System.Web.Cach ing.Cache.NoAbs oluteExpiration , TimeSpan.FromMi nutes(10),
System.Web.Cach ing.CacheItemPr iority.Default,
new System.Web.Cach ing.CacheItemRe movedCallback(i temRemoved));

but the Item is removed from the cache (with reason of underused) after
something like 1 minute.

What is going on here?

Thanks,
Nadav
Feb 13 '07 #2
Thanks for Karl's input.

Hello Nadav,

Assume that you haven't used webfarm or webgarden for your application(onl y
hosted on a single server and single worker process). As Karl has
mentioned, you can first check the memory pressure on the server machine.
There are some cases that the ASP.NET web application will restart or the
worker process will recycle, this will surely cause the ASP.NET
applciation's cache data be lost.

For ASP.NET worker process recycle, you can try looking up the server's
event log to see whether there is worker process recycle entries there. For
ASP.NET application restart, you can use the Application_End ,
application_Sta rt event to do logging.

#Logging ASP.NET Application Shutdown Events
http://weblogs.asp.net/scottgu/archi...14/433194.aspx

Also, for ASP.NET application/process healthy monitoring, you can also
utilize the windows performance counters. Here are some specific categories
and counters

**Process
**Thread
**Processor
**Memory
** .NET CLR Data
**.NET CLR Exceptions
** .NET CLR Jit
**.NET CLR LocksAndThreads
**.NET CLR Memory
** ASP.NET v2.0.50727
** ASP.NET Applications v2.0.50727

Hope this also helps some for your troubleshooting .

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

=============== =============== =============== =====

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.

=============== =============== =============== =====

This posting is provided "AS IS" with no warranties, and confers no rights.

Feb 14 '07 #3
Hi Steven,

Yes, the machine is under memory pressure
(I assume that Page File usage of 1.5GB with 1GB of ram is considered memory
pressure).
Will recycling of the worker process interfere with debugging?
I mean, can the web server recycle the worker process while I'm debugging
the application without me noticing?

(by the way I'm using the internal web server of VS2005, not IIS)

If the problem IS memory pressure, is there some way for me to prevent this
recycling happening?
Some items on the cache I can recreate if needed, so this is not a problem.
But in some cases, at the place I'm reading the item from the cache, I can't
recreate the item, so I MUST insure that the object will remain in the cache
for a certain amount of time.

I'm trying to implement a DynamicImage control where an event handler of the
control creates the image and stores it in the cache, and the HttpHandler
later reads it from the cache and returns it. The HttpHandler CAN'T recreate
the image!

Thanks,
Nadav
Feb 14 '07 #4
Thanks for your reply Nadav,

If you're debugging the web application(the worker process), I think you
can be awared of the application restart or worker process recycle. Since
you mentioned that your machine does be under memory pressure, I think you
can try changing your cached item's Priority to see whether the problem
remains. e.g.

Cache.Insert("D SN", connectionStrin g, null, DateTime.Now.Ad dMinutes(2),
TimeSpan.Zero, CacheItemPriori ty.NotRemovable , null);
#CacheItemPrior ity Enumeration
http://msdn2.microsoft.com/en-us/lib...cheitempriorit
y(VS.80).aspx
As the document mentioned, the "NotRemovab le" priority can help prevent
your cached item be removed when system free memory.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.


Feb 15 '07 #5
If you REQUIRE an item to be available, you shouldn't use the cache,
regardless of what the priority is.

You must use the Application object, which WILL pin the object in memory.

However, an app recycle will still cause application items to get dropped.

Karl

--
http://www.openmymind.net/
http://www.fuelindustries.com/
"Steven Cheng[MSFT]" <st*****@online .microsoft.comw rote in message
news:Fy******** ******@TK2MSFTN GHUB02.phx.gbl. ..
Thanks for your reply Nadav,

If you're debugging the web application(the worker process), I think you
can be awared of the application restart or worker process recycle. Since
you mentioned that your machine does be under memory pressure, I think you
can try changing your cached item's Priority to see whether the problem
remains. e.g.

Cache.Insert("D SN", connectionStrin g, null, DateTime.Now.Ad dMinutes(2),
TimeSpan.Zero, CacheItemPriori ty.NotRemovable , null);
#CacheItemPrior ity Enumeration
http://msdn2.microsoft.com/en-us/lib...cheitempriorit
y(VS.80).aspx
As the document mentioned, the "NotRemovab le" priority can help prevent
your cached item be removed when system free memory.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no
rights.



Feb 15 '07 #6
Hi Steven,

Thanks, this is exactly what I need.

I tried to change the CacheItemPriori ty to High, Some how I must have missed
the
NotRemovable priority!

I will change my code and see if it solved the problem.

Thanks again
Nadav

"Steven Cheng[MSFT]" wrote:
Thanks for your reply Nadav,

If you're debugging the web application(the worker process), I think you
can be awared of the application restart or worker process recycle. Since
you mentioned that your machine does be under memory pressure, I think you
can try changing your cached item's Priority to see whether the problem
remains. e.g.

Cache.Insert("D SN", connectionStrin g, null, DateTime.Now.Ad dMinutes(2),
TimeSpan.Zero, CacheItemPriori ty.NotRemovable , null);
#CacheItemPrior ity Enumeration
http://msdn2.microsoft.com/en-us/lib...cheitempriorit
y(VS.80).aspx
As the document mentioned, the "NotRemovab le" priority can help prevent
your cached item be removed when system free memory.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.


Feb 15 '07 #7
thanks for your reply Nadav,

If you meet any further problem, please feel free to followup here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.

Feb 16 '07 #8
Hi Karl,

The problem with the Application object is that objects stored there will
NEVER expire unless I (i.e. my code) explicitly remove them.
I don't want to have to add code to handle this
Especially when I sometimes don't know when I don't need this data anymore...

I WANT my data to be expired after a period of inactivity without having to
recycle the whole application.
All I want is to be sure that the object will NOT be removed before I can
use it.
A pity you can't specify a minimum interval when the cache will NOT expire
it because of memory pressure and after that it can.

Thanks,
Nadav
Feb 18 '07 #9
Hi Nadav,

So does the "NotRemovab le" priority finally resolve the previous problem?

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.

Feb 19 '07 #10

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

Similar topics

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
2275
by: Peter Morris [Droopy eyes software] | last post by:
Hi all In my login form (forms authentication) I check that the login is valid, retrieve an "Author" object, and keep track of the author's roles. string roles; if (author.IsAdministrator) roles = new string {"Admin", "Member"}; else roles = new string {"Member"};
4
2280
by: steroche | last post by:
I would REALLY appreciate help please please please! Im sure it is probably blindingly obvious to most of you but I am totally in the dark here!I am lost - i thought i had finally figured out this dataSet updating lark when i realised that i think i am right back at square 1!!! Here's my scenario - i have a SQLDB and i retrieve all my data from that into a dataset and display this to a datagrid(WebForm). I have got this grid sorted and...
4
1884
by: c676228 | last post by:
Hi all, the data disappearing problem occurs to all my controls even my regualr web control like asp:textbox, when I click back button in web browser from second page to first page and then click continue button on the first page to second page again, all the data entered , even in web server control(not user controls defined by myself.) all disappear. What's going on. I thought dealing with .net should be much easier, did I miss...
3
1926
by: Aryan | last post by:
Hi, I have problem related to Caching of data. I am reading large xml file and putting this xml in dataset, since this dataset will contain many datatable's inside. And each datatable might be big in data. Each user will contain its seperate xml file, so when I create xml file for each user, I am putting this xml DataSet in Cache object, but when I try to populate my controls using Cache object, I am faching weired problem. As some times...
3
1321
by: Arjen | last post by:
Hi, I have a public class 'settings' with a public static void 'loadsettings'. Inside 'loadsettings' I go to public static 'loadpagesettings'. Inside this function I have a problem. 1. I create an arraylist 2. Load the arraylist with items from the cache
5
1373
by: Harry Keck | last post by:
I have an application that I recently converted to 2.0 from 1.1. This application is relying on data stored at HttpContext.Current.Cache. When I run in 1.1 the data stays available in the cache, but when I run the 2.0 converted application, once I change pages, the cache is emptied. Is this just a setting that I am missing, or has something changed about the way that the cache is managed?
5
1310
by: ThunderMusic | last post by:
Hi, I always refer to this page to know the order of events in a page : http://weblogs.asp.net/jeff/archive/2004/07/04/172683.aspx but this time, I'm mystified... I have a Control called "ImagePreloader" I placed in the head of my MasterPage (aspx)... in the Init of the "ImagePreloader", I put the instance in the HTTPContext.Current.Cache... and provide a static method so other controls can have access to the ImagePreloader... On a P...
1
3394
by: neovantage | last post by:
Hey all, I am using a PHP script which creates headings at run time in a sense at page execution. I am stuck a with a very little problem which i am sure i will have the solution from experts. The problem is when it creates transparent PNG format image then and it pixel ate the image. e.g. If i am using a gradient in background then it vary in color range. Now when i used that php script it generates image successfully but it pixel ate...
0
9647
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
9489
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10100
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9959
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8988
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...
0
6744
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5528
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3665
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2893
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.