473,396 Members | 2,037 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 4064
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

28
by: Jon Davis | last post by:
If I have a class with a virtual method, and a child class that overrides the virtual method, and then I create an instance of the child class AS A base class... BaseClass bc = new ChildClass();...
5
by: RickDee | last post by:
Please help, anybody. I am trying to write a program so that it can launch an exe file ( which is also genereated in C# ) and then simulate the button clicking and invoke the methods inside the...
0
by: usamedb208 | last post by:
Hello. I have a web method that make a call to database. I set cacheDuration attribute to 0, -1,1, anything but it caches results every time when I make a call to this web method with the same...
0
by: Rob C | last post by:
Hi, I was implementing a simple example of a web service that uses caching: public String CachedString(int input) { return "The time is " + DateTime.Now.ToLongTimeString(); } When I use...
1
by: jonel | last post by:
I have the CacheDuration attribute set for 60 seconds as show below: <WebMethod(CacheDuration:=60, Description:="Method to demonstrate caching")> _ Public Function CachedString(ByVal inputInt As...
0
by: Arpan | last post by:
I successfully created a DLL named "DBServices.dll" using the following code in a class file: Imports System Imports System.Data Imports System.Data.SqlClient Imports System.Web.Services ...
0
by: archana | last post by:
Hi all, I am developing one web service and i want to use caching in that. I set cacheduration as 60 seconds. So what i am expecting is withint 60 second if i recalled method it should give...
7
by: cbmeeks | last post by:
Hope I'm using the right terminology. Anyway, say I have a class like: class Animal { public double GetValues() {......} public void FilterBy(string text); {......}
11
by: =?Utf-8?B?QkxVRVNUQVI=?= | last post by:
Here is the link of the website http://www.smartcharlotte2050.com/YourThoughts.asp I have been told to change only the form action part of this site.which is to "response.asp" Here the method...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.