Call Web service-application cache in asp.net atlas to reduce server overhead

Source: Internet
Author: User
Tags current time datetime html tags
asp.net|cache|web| Server

For some complex, requiring a long time to complete, and the real-time requirements are not very high service, the choice of cache is often an effective way to improve efficiency. NET's Web service implementation to fully consider the need for cache, you need to simply set up to enable cache. Calls to Web service in Atlas can also take advantage of this cache mechanism to reduce unnecessary overhead on the server side.

To enable the cache for Web service, you only need to add the following properties to the WebMethod declaration:

[WebMethod (CacheDuration = 5)]

Where the CacheDuration value represents the cache time, in seconds.

But this cache method is provided by the Web service, and Atlas knows nothing about it, and it is sent to the server each time it is invoked. So for the network latency on the user's impact, this cache can not improve.

Let's use a sample program to learn more about the cache for Web service.

First write a Web Service, return the current time, and specify CacheDuration for 5 seconds:

[WebService (Namespace = "http://tempuri.org/")]
[WebServiceBinding (ConformsTo = wsiprofiles.basicprofile1_1)]
public class CachedWebService:System.Web.Services.WebService
{
[WebMethod (CacheDuration = 5)]
Public DateTime Getgurrenttime ()
{
return datetime.now;
}
}

Then create an Atlas page, add ScriptManager and reference the Web Service in it:

<atlas:scriptmanager runat= "Server" id= "ScriptManager" >
<Services>
<atlas:servicereference path= "Cachedwebservice.asmx"/>
</Services>
</atlas:ScriptManager>

Add some HTML tags to call the Web service and display the results:

<input id= "Btninvoke" type= "button" value= "Invoke"/>
<div id= "Result" >
</div>

Finally, the JavaScript section, where we will display the results of each call to the page for easy analysis:

function Btninvoke_onclick () {
Cachedwebservice.getgurrenttime (oncompleted);
}
function oncompleted (Result) {
$ (' result '). InnerHTML + = result + "<br/>";
}

The following test in the browser, after many clicks on the button, the results are as follows, you can see the role of cache:

Also, as you can see in fiddler, these requests are actually sent to the server, and the cache is only implemented on the server side:







Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.