CacheDuration in web method not working

  • Thread starter Thread starter archana
  • Start date Start date
A

archana

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.
 
archana said:
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
 
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.

archana said:
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
 
archana said:
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
 

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

Back
Top