Application Cache question

J

J055

Hi

The following code works on my develeopment machine using the VS web server.
When I run the application on 2 other Windows 2003/IIS 6 servers no caching
seems to take place at all. Can someone explain what I might be doing wrong
or what to look out for? What's the differece between IIS and VS web server?
The IIS servers seem to have enough memory.

public DataTable GetAll()
{
DataTable dt;

// try to retrieve item from cache
dt = (DataTable)_context.Cache[_cacheKeyName];

if (dt == null)
{
dt = tableAdapter.GetAll();
_context.Cache.Insert(_cacheKeyName, dt, null, Cache.NoAbsoluteExpiration,
TimeSpan.FromSeconds(600));
}
return dt;
}


Many thanks

Andrew
 
S

Steven Cheng[MSFT]

Hi Andrew,

From your description, you have an ASP.NET 2.0 application which use cache
to store objects. You found the application work fine on dev machine(in VS
2005 Test server) but can not persist cache on product server(win2k3 iis),
correct?

Based on the code snippet you provided, I think the code logic should be
correct and as you mentioned it work on dev machine, therefore, the problem
is likely due to the deployment environment. Of course, there is no
particular limitation on Application cache between IIS hosted and VS 2005
test server enviornment. Would you tried the following things to further
simplify the issue?

** Create a new empty project and add a simple page to dedicated on using
cache to store objects(you can try both small objects and large objects)

** In the windows performance counters, you can add the ASP.NET cache
related counters(such as "CACHE API Entries" ) under the "ASP.NET APPs
V2.0....." category.

If the problem can be even reproted through such as simple project, it will
make the problem much clearer.

If you have any other finding, please also feel free to post here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead



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

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.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/subscriptions/support/default.aspx.

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


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




--------------------
From: "J055" <[email protected]>
Subject: Application Cache question
Date: Mon, 3 Sep 2007 20:11:53 +0100


Hi

The following code works on my develeopment machine using the VS web server.
When I run the application on 2 other Windows 2003/IIS 6 servers no caching
seems to take place at all. Can someone explain what I might be doing wrong
or what to look out for? What's the differece between IIS and VS web server?
The IIS servers seem to have enough memory.

public DataTable GetAll()
{
DataTable dt;

// try to retrieve item from cache
dt = (DataTable)_context.Cache[_cacheKeyName];

if (dt == null)
{
dt = tableAdapter.GetAll();
_context.Cache.Insert(_cacheKeyName, dt, null, Cache.NoAbsoluteExpiration,
TimeSpan.FromSeconds(600));
}
return dt;
}


Many thanks

Andrew
 
J

J055

Hi Steven

I can see that small objects seem to work. It doesn't really help me because
on the development machine large objects work too.

On the main server that seems to be having problems I watched some of the
performance counters you suggested. The object I'm attempting to cache is a
Dictionary<int, string> with around 20 entries.

Cache API Entries: 0 - 2 (mostly 0)
Cache API Hit Ratio: 51.638
Cache API Hits: 268
Cache API Misses: 251

I'm afraid though that I have no idea how to interpret these figures. Does
it suggest anything to you?

Thanks again
Andrew



Steven Cheng said:
Hi Andrew,

From your description, you have an ASP.NET 2.0 application which use cache
to store objects. You found the application work fine on dev machine(in VS
2005 Test server) but can not persist cache on product server(win2k3 iis),
correct?

Based on the code snippet you provided, I think the code logic should be
correct and as you mentioned it work on dev machine, therefore, the
problem
is likely due to the deployment environment. Of course, there is no
particular limitation on Application cache between IIS hosted and VS 2005
test server enviornment. Would you tried the following things to further
simplify the issue?

** Create a new empty project and add a simple page to dedicated on using
cache to store objects(you can try both small objects and large objects)

** In the windows performance counters, you can add the ASP.NET cache
related counters(such as "CACHE API Entries" ) under the "ASP.NET APPs
V2.0....." category.

If the problem can be even reproted through such as simple project, it
will
make the problem much clearer.

If you have any other finding, please also feel free to post here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead



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

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.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/subscriptions/support/default.aspx.

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


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




--------------------
From: "J055" <[email protected]>
Subject: Application Cache question
Date: Mon, 3 Sep 2007 20:11:53 +0100


Hi

The following code works on my develeopment machine using the VS web server.
When I run the application on 2 other Windows 2003/IIS 6 servers no caching
seems to take place at all. Can someone explain what I might be doing wrong
or what to look out for? What's the differece between IIS and VS web server?
The IIS servers seem to have enough memory.

public DataTable GetAll()
{
DataTable dt;

// try to retrieve item from cache
dt = (DataTable)_context.Cache[_cacheKeyName];

if (dt == null)
{
dt = tableAdapter.GetAll();
_context.Cache.Insert(_cacheKeyName, dt, null, Cache.NoAbsoluteExpiration,
TimeSpan.FromSeconds(600));
}
return dt;
}


Many thanks

Andrew
 
J

J055

Hi

I've done a little more research. I understand the counter stats better now.
I checked the data being retrieved from SQL Server and it's around 15,000
Bytes (133 rows), it gets pulled into a DataTable then a Dictionary. I guess
that has little to do with why the caching doesn't work so well.

The settings are to use sliding expiration for 5 minutes. Even though the
hit ratio is 50% (which I think is bad anyway), the cache seems to be
cleared almost immediately most of the time.

When I recycle the IIS App pool the cache seems to work better for a few
minutes and then degrades again shortly after.

I'd like to cache a lot more objeects in the application but I need to
undertstand what this problem is first. Any ideas?

Thanks
Andrew
 
S

Steven Cheng[MSFT]

Thanks for your reply Andrew,

Yes, for the counters, the "CACHE API Entries" can help indicate the cache
items added the user(exclude the ones added by system), you can check it to
see whether the number matches the items your code have added.

As you said the DataTable object is around 15,000 Bytes, is your
application frequently caching such objects? If so, it may produce some
memory pressure. You can have a look at the EventLog to see whether there
is entry indicate the ASP.NET worker process has recycled frequently or
whether the ASP.NET application is restarting constantly. Application
Restart may cause the Cache objects lost. BTW, is it possible to repro
the same problem through a very simple project with a single page to cache
some large datatables(you may use code to manually create some datatable
objects for test). If so, you can also send me the project and let me
perform some local test.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


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


--------------------
 
S

Steven Cheng[MSFT]

Hi Andrew,

Have you got any progress on this? I'm still monitoring on this issue and
would like to check the issue status with you.

Also, based on the nature of this problem, it may not be quite easy and
efficient to troubleshoot through newsgroup communication. Therefore, if
this is an urgent issue, I would suggest you consider contact CSS phone
support directly. Anyway, if you need continual help from us, please feel
free to post here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,825
Latest member
VernonQuy6

Latest Threads

Top