Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

caching within a web service

Hi Everybody,

I'm creating a standard web service using .Net (C#). The exposed API is
supposed to get many hits per second (hundreds). I am in need of a caching
mechanism. Something that will allow me to store information in memory and
access it from any of the web service calls instance.

The most intuitive answer is to create a free-threaded object which will
store a sorted list or something of the sort, and will serve as the caching
mechanism. However, how can I ensure that this object doesn't get garbage
collected if the object is suddenly not used for a little while? Another
question is whether this object would become my bottleneck (I assume I don't
need to lock while reading cached information, only when writing, but does
this make it fast enough?)

If there's some other magic for creating a caching mechanism in such a
situation, I'd love to hear about it.

Your opinion is highly appreciated. Thanks,

--itai
[1034 byte] By [Itai Raz] at [2007-11-9 19:48:33]
# 1 Re: caching within a web service
If I may add to my own question (and offer a solution). Forgive me for not
mentioning it before, but I could, of course, use the Global class and
expose a sorted list or other objects as my caching mechanism. This ensures
availability of this caching object from any thread of IIS in this web
service.

Any opinions about performance bottleneck issues here? Any other/better
ideas?

Thanks,

--itai

"Itai Raz" <notreadingthis@hotmail.com> wrote in message
news:3f640c69@tnews.web.dev-archive.com...
> Hi Everybody,
>
> I'm creating a standard web service using .Net (C#). The exposed API is
> supposed to get many hits per second (hundreds). I am in need of a caching
> mechanism. Something that will allow me to store information in memory and
> access it from any of the web service calls instance.
>
> The most intuitive answer is to create a free-threaded object which will
> store a sorted list or something of the sort, and will serve as the
caching
> mechanism. However, how can I ensure that this object doesn't get garbage
> collected if the object is suddenly not used for a little while? Another
> question is whether this object would become my bottleneck (I assume I
don't
> need to lock while reading cached information, only when writing, but does
> this make it fast enough?)
>
> If there's some other magic for creating a caching mechanism in such a
> situation, I'd love to hear about it.
>
> Your opinion is highly appreciated. Thanks,
>
> --itai
>
>
Itai Raz at 2007-11-11 21:57:55 >
# 2 Re: caching within a web service
Itai,
> If there's some other magic for creating a caching mechanism in such a
> situation, I'd love to hear about it.

ASP.NET (of which Web Services is a part of) provides very strong Caching
support

You can use this support in one of two ways:

1. Specify the CacheDuration parameter of the WebMethodAttribute. Which sets
the number of seconds the response should be held in the cache.

2. Use the WebService.Context property to get at the Cache object to store
items in the ASP.NET Cache.

For details on both & other options see:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnservice/html/service04172002.asp

Hope this helps
Jay

"Itai Raz" <notreadingthis@hotmail.com> wrote in message
news:3f640c69@tnews.web.dev-archive.com...
> Hi Everybody,
>
> I'm creating a standard web service using .Net (C#). The exposed API is
> supposed to get many hits per second (hundreds). I am in need of a caching
> mechanism. Something that will allow me to store information in memory and
> access it from any of the web service calls instance.
>
> The most intuitive answer is to create a free-threaded object which will
> store a sorted list or something of the sort, and will serve as the
caching
> mechanism. However, how can I ensure that this object doesn't get garbage
> collected if the object is suddenly not used for a little while? Another
> question is whether this object would become my bottleneck (I assume I
don't
> need to lock while reading cached information, only when writing, but does
> this make it fast enough?)
>
> If there's some other magic for creating a caching mechanism in such a
> situation, I'd love to hear about it.
>
> Your opinion is highly appreciated. Thanks,
>
> --itai
>
>
Jay B. Harlow [MVP - Outlook] at 2007-11-11 21:58:59 >
# 3 Re: caching within a web service
Thanks for you reply. I'm looking at it right now.

Incidentally, how about using the global class (from global.asax), and store
a caching object within it?

--
--itai
"Jay B. Harlow [MVP - Outlook]" <Jay_Harlow@email.msn.com> wrote in message
news:3f6482f9$1@tnews.web.dev-archive.com...
> Itai,
> > If there's some other magic for creating a caching mechanism in such a
> > situation, I'd love to hear about it.
>
> ASP.NET (of which Web Services is a part of) provides very strong Caching
> support
>
> You can use this support in one of two ways:
>
> 1. Specify the CacheDuration parameter of the WebMethodAttribute. Which
sets
> the number of seconds the response should be held in the cache.
>
> 2. Use the WebService.Context property to get at the Cache object to store
> items in the ASP.NET Cache.
>
> For details on both & other options see:
>
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnservice/html/service04172002.asp
>
> Hope this helps
> Jay
>
> "Itai Raz" <notreadingthis@hotmail.com> wrote in message
> news:3f640c69@tnews.web.dev-archive.com...
> > Hi Everybody,
> >
> > I'm creating a standard web service using .Net (C#). The exposed API is
> > supposed to get many hits per second (hundreds). I am in need of a
caching
> > mechanism. Something that will allow me to store information in memory
and
> > access it from any of the web service calls instance.
> >
> > The most intuitive answer is to create a free-threaded object which will
> > store a sorted list or something of the sort, and will serve as the
> caching
> > mechanism. However, how can I ensure that this object doesn't get
garbage
> > collected if the object is suddenly not used for a little while? Another
> > question is whether this object would become my bottleneck (I assume I
> don't
> > need to lock while reading cached information, only when writing, but
does
> > this make it fast enough?)
> >
> > If there's some other magic for creating a caching mechanism in such a
> > situation, I'd love to hear about it.
> >
> > Your opinion is highly appreciated. Thanks,
> >
> > --itai
> >
> >
>
>
Itai Raz at 2007-11-11 22:00:03 >
# 4 Re: caching within a web service
Itai,
The article I gave the link to discusses that option.

Hope this helps
Jay

"Itai Raz" <notreadingthis@hotmail.com> wrote in message
news:3f67eb08$1@tnews.web.dev-archive.com...
> Thanks for you reply. I'm looking at it right now.
>
> Incidentally, how about using the global class (from global.asax), and
store
> a caching object within it?
>
> --
> --itai
> "Jay B. Harlow [MVP - Outlook]" <Jay_Harlow@email.msn.com> wrote in
message
> news:3f6482f9$1@tnews.web.dev-archive.com...
> > Itai,
> > > If there's some other magic for creating a caching mechanism in such a
> > > situation, I'd love to hear about it.
> >
> > ASP.NET (of which Web Services is a part of) provides very strong
Caching
> > support
> >
> > You can use this support in one of two ways:
> >
> > 1. Specify the CacheDuration parameter of the WebMethodAttribute. Which
> sets
> > the number of seconds the response should be held in the cache.
> >
> > 2. Use the WebService.Context property to get at the Cache object to
store
> > items in the ASP.NET Cache.
> >
> > For details on both & other options see:
> >
>
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnservice/html/service04172002.asp
> >
> > Hope this helps
> > Jay
> >
> > "Itai Raz" <notreadingthis@hotmail.com> wrote in message
> > news:3f640c69@tnews.web.dev-archive.com...
> > > Hi Everybody,
> > >
> > > I'm creating a standard web service using .Net (C#). The exposed API
is
> > > supposed to get many hits per second (hundreds). I am in need of a
> caching
> > > mechanism. Something that will allow me to store information in memory
> and
> > > access it from any of the web service calls instance.
> > >
> > > The most intuitive answer is to create a free-threaded object which
will
> > > store a sorted list or something of the sort, and will serve as the
> > caching
> > > mechanism. However, how can I ensure that this object doesn't get
> garbage
> > > collected if the object is suddenly not used for a little while?
Another
> > > question is whether this object would become my bottleneck (I assume I
> > don't
> > > need to lock while reading cached information, only when writing, but
> does
> > > this make it fast enough?)
> > >
> > > If there's some other magic for creating a caching mechanism in such a
> > > situation, I'd love to hear about it.
> > >
> > > Your opinion is highly appreciated. Thanks,
> > >
> > > --itai
> > >
> > >
> >
> >
>
>
Jay B. Harlow [MVP - Outlook] at 2007-11-11 22:00:58 >