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: