469,283 Members | 2,192 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,283 developers. It's quick & easy.

CacheDuration in web method not working

hi all.
I am having one web service in c#.net where in i am using
cacheduration.

I have one property as below:

[WebMethod(EnableSession=true, CacheDuration=20)]
get
{

return Application["MyServiceUsage"].ToString();

}

[WebMethod(EnableSession=true, CacheDuration=20)]
set
{
if (Application["MyServiceUsage"] == null)
{
Application["MyServiceUsage"] = value +
DateTime.Now.Minute.ToString(); ;
}
}

So what i am expecting that after each 20 second it should clear cache
and set new value.

But when i run web service every time it is showing me first value only
and not updating value of variable with is tehre in application.

Can some one help me in this issue,
If i am wrong in this logic please correct me.

Thanks in advance.

Feb 21 '06 #1
3 3787
archana wrote:
I am having one web service in c#.net where in i am using
cacheduration.

I have one property as below:

[WebMethod(EnableSession=true, CacheDuration=20)]
get
{

return Application["MyServiceUsage"].ToString();

}

[WebMethod(EnableSession=true, CacheDuration=20)]
set
{
if (Application["MyServiceUsage"] == null)
{
Application["MyServiceUsage"] = value +
DateTime.Now.Minute.ToString(); ;
}
}

So what i am expecting that after each 20 second it should clear cache
and set new value.


After 20 seconds, the property will be re-evaluated next time the
service is requested.

However, you've got a second level of caching there - the Application
property - it's only going to be updated once with the code you've got.

Why are you caching the setter in the first place, by the way? That
seems to be pretty pointless - or worse, because it's trying to update
something rather than to fetch data.

Jon

Feb 21 '06 #2
Hi
thanks for ur reply.

But his example i found in msdn itself.

And it is stated that 'When caching is enabled requests and responses
are held in memory on the server for at least the cache duration '.
What i want is i have one method in web service for opening database
connection.

For getting information such as databsename, server name i am using
application variable along with cacheing.

And what i want is to keep this information into server for some
specific amount of time and then just clear that information from
server.

If i am doing wrong please let me know about that.

If u know any other alternative of doing this, then please let me know.

thanks in advance.
Jon Skeet [C# MVP] wrote:
archana wrote:
I am having one web service in c#.net where in i am using
cacheduration.

I have one property as below:

[WebMethod(EnableSession=true, CacheDuration=20)]
get
{

return Application["MyServiceUsage"].ToString();

}

[WebMethod(EnableSession=true, CacheDuration=20)]
set
{
if (Application["MyServiceUsage"] == null)
{
Application["MyServiceUsage"] = value +
DateTime.Now.Minute.ToString(); ;
}
}

So what i am expecting that after each 20 second it should clear cache
and set new value.


After 20 seconds, the property will be re-evaluated next time the
service is requested.

However, you've got a second level of caching there - the Application
property - it's only going to be updated once with the code you've got.

Why are you caching the setter in the first place, by the way? That
seems to be pretty pointless - or worse, because it's trying to update
something rather than to fetch data.

Jon


Feb 22 '06 #3
archana wrote:
thanks for ur reply.

But his example i found in msdn itself.
Unfortunately that doesn't make it a good example :(
And it is stated that 'When caching is enabled requests and responses
are held in memory on the server for at least the cache duration '.


Yes, and there's nothing to indicate that hasn't happened.

There are two levels of caching in the code you posted - there's the
caching of the WebMethod, and the caching in the Application.

I suggest that to understand the WebMethod caching better, you create a
single property of LastTimeExecuted which just returns
DateTime.Now.ToString(). Execute that repeatedly, and you should see it
only update every 20 seconds (or however long you set the cache
duration to be).

Jon

Feb 22 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

28 posts views Thread by Jon Davis | last post: by
reply views Thread by usamedb208 | last post: by
reply views Thread by Rob C | last post: by
1 post views Thread by jonel | last post: by
reply views Thread by Arpan | last post: by
reply views Thread by archana | last post: by
7 posts views Thread by cbmeeks | last post: by
11 posts views Thread by =?Utf-8?B?QkxVRVNUQVI=?= | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.