public class CacheHandler : IHttpHandler
    {

        
public void ProcessRequest(HttpContext context)
        {
            OutputCachedPage page 
= new OutputCachedPage(new OutputCacheParameters
            {
                Duration 
= 60,
                Location 
= OutputCacheLocation.Server,
                VaryByParam 
= "v"
            });
            page.ProcessRequest(HttpContext.Current);

            context.Response.Write(DateTime.Now);
        }

        
public bool IsReusable
        {
            
get
            {
                
return false;
            }
        }
        
private sealed class OutputCachedPage : Page
        {
            
private OutputCacheParameters _cacheSettings;

            
public OutputCachedPage(OutputCacheParameters cacheSettings)
            {
                
// Tracing requires Page IDs to be unique.
                ID = Guid.NewGuid().ToString();
                _cacheSettings 
= cacheSettings;
            }

            
protected override void FrameworkInitialize()
            {
                
// when you put the <%@ OutputCache %> directive on a page, the generated code calls InitOutputCache() from here
                base.FrameworkInitialize();
                InitOutputCache(_cacheSettings);
            }
        }
    }

相关文章:

  • 2021-10-16
  • 2021-06-25
  • 2022-12-23
  • 2021-11-26
  • 2022-01-31
  • 2021-07-14
  • 2022-12-23
  • 2021-12-28
猜你喜欢
  • 2022-12-23
  • 2021-12-18
  • 2022-12-23
  • 2021-07-23
相关资源
相似解决方案