开发者

Caching with Sliding Expiration in ASP.NET Page Methods

开发者 https://www.devze.com 2023-02-14 20:36 出处:网络
I know that when declaring a page method in ASP.NET, I can specify a CacheDuration like so: [WebMethod(CacheDuration=60)]

I know that when declaring a page method in ASP.NET, I can specify a CacheDuration like so:

[WebMethod(CacheDuration=60)]
public static void Foo()
{
    //TODO Bar
}  

But from what I understand, CacheDur开发者_StackOverflowation only supports absolute expiration. I want to have sliding expiration. So that leads me to believe that I need to access the System.Web.Caching.Cache object somehow. But, since page methods are static, and this is essentially a standalone web service, I'm not sure how to access it statically. The only ways I have seen on Google rely on getting it from the HttpContext. But, there is no HttpContext available to me here, right?

Or, do I need to use the System.Runtime.Caching.MemoryCache to do my own caching?

Much thanks.


you can access

System.Web.HttpContext.Current.Cache

from your page method.

0

精彩评论

暂无评论...
验证码 换一张
取 消