all groups > dotnet web services > february 2006 >
You're in the

dotnet web services

group:

Caching in web services


Caching in web services beaverme
2/28/2006 5:17:33 AM
dotnet web services: Hi,
I have a series of web services. They all use require authentication and
successful authentication instantiates a Customer object which is used for
billing purposes. All of this is handled by a common base class. I'd like to
cache these Customer objects so that I don't have to make a database call
each time the service is called but I'm not sure of the best strategy. The
System.Web.Caching.Cache object seems to provide the required functionality.
It's very easy to use from a regular .aspx page but I'm not sure how to
implement equivalent functionality in my base class.

Please could you recommend an approach?

Regards,

Re: Caching in web services Martin Kulov
2/28/2006 11:20:45 PM
[quoted text, click to view]

So you need to call the web services from ASP.NET application. Is that
correct?
I think System.Web.Caching.Cache will not be a good choice since it is a
global object and it seems you need per session object . Also Cache object
expires when the there is a need for more memory, so you should check it for
null every single time you use it.
May be you should consider Session object in ASP.NET. It is per user
(session) and make sure that you implement a scale strategy in case your
logical design requires it.

HTH,

--
Martin Kulov
http://www.codeattest.com/blogs/martin

MCT
MCSD.NET Early Achiever



Re: Caching in web services stcheng NO[at]SPAM online.microsoft.com
3/1/2006 2:14:41 AM
Hi Lee,

If the data object is used at webservice server-side and will be frequently
accessed after the first time it is created, I think it is reasonable to
cache it. And as for how to cache it , we have several approachs:

1. Use SessionState, this is possible for ASP.NET webserivce and will help
us store the data object per client user session. However, there're some
setting we need to pay attention, see the following MSDN article:

#Using ASP.NET Session State in a Web Service
http://msdn.microsoft.com/library/en-us/dnservice/html/service08062002.asp?f
rame=true

Also, for session state data, there is no expiration policy we can use, we
need to manually clear it after finishing use them or let them expire when
session timeout.

2. Use Application Cache, I prefer this approach since the ASP.NET
System.Web.Cache provide rich functionality such as cache dependency
supports so that we can make the cached object automatically expire when
some certain dependency changes. Also. in 2.0 there comes the new Sql
Database cache dependency which is rather powerful. However, since Cache
is application scope storage, we need to manually use our own index to
separate data for individual client user.

Hope this helps.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
AddThis Social Bookmark Button