473,385 Members | 2,004 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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.Cache.Insert(key, userInfo, null,
System.Web.Caching.Cache.NoAbsoluteExpiration, TimeSpan.FromMinutes(10),
System.Web.Caching.CacheItemPriority.Default,
new System.Web.Caching.CacheItemRemovedCallback(itemRe moved));

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 4307
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********@newsgroup.nospamwrote in message
news:15**********************************@microsof t.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.Cache.Insert(key, userInfo, null,
System.Web.Caching.Cache.NoAbsoluteExpiration, TimeSpan.FromMinutes(10),
System.Web.Caching.CacheItemPriority.Default,
new System.Web.Caching.CacheItemRemovedCallback(itemRe moved));

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(only
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_Start 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("DSN", connectionString, null, DateTime.Now.AddMinutes(2),
TimeSpan.Zero, CacheItemPriority.NotRemovable, null);
#CacheItemPriority Enumeration
http://msdn2.microsoft.com/en-us/lib...cheitempriorit
y(VS.80).aspx
As the document mentioned, the "NotRemovable" 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.comwrote in message
news:Fy**************@TK2MSFTNGHUB02.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("DSN", connectionString, null, DateTime.Now.AddMinutes(2),
TimeSpan.Zero, CacheItemPriority.NotRemovable, null);
#CacheItemPriority Enumeration
http://msdn2.microsoft.com/en-us/lib...cheitempriorit
y(VS.80).aspx
As the document mentioned, the "NotRemovable" 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 CacheItemPriority 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("DSN", connectionString, null, DateTime.Now.AddMinutes(2),
TimeSpan.Zero, CacheItemPriority.NotRemovable, null);
#CacheItemPriority Enumeration
http://msdn2.microsoft.com/en-us/lib...cheitempriorit
y(VS.80).aspx
As the document mentioned, the "NotRemovable" 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 "NotRemovable" 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
Hi Steven,

Yes, the NotRemovable priority did fix the problem.
So I didn't reply sooner.

Thanks for your help.
Nadav

"Steven Cheng[MSFT]" wrote:
Hi Nadav,

So does the "NotRemovable" 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 21 '07 #11

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

Similar topics

4
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 -...
1
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)...
4
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...
4
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...
3
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...
3
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...
5
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,...
5
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...
1
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. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
0
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...
0
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,...
0
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...

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.