I have a long running web service (3-5 mins) which returns a large custom object.
I declare the web method like this...
public class MyService : System.Web.Services.WebService
{
[WebMethod(CacheDuration=86400)]
[XmlInclude(typeof(MyObject))]
public MyObject Items(string myParam)
{
return new MyObject(myParam);
}
}
I then consume the service in a classic ASP.NET 4.0 app and cache the elements of "Items" like this...
protected MyService.MyObject servObj = new MyService.MyObject();
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
if (Cache["elems1"] == null)
{
MyObject items = servObj.Items("myParam");
Cache.Insert("elems1", servObj.elems1, null, DateTime.MaxValue, TimeSpan.FromHours(24));
Cache.Insert("elems2", servObj.elems2, null, DateTime.MaxValue, TimeSpan.FromHours(24));
}
}
}
When I run the app it seems that the web service cache is sometimes available and sometimes not i.e. it is not lasting the specified duration. The web service runs in it's own app pool on IIS.
Any ideas why? Is there a smarter way to cache the web service results?