简体   繁体   English

从同一ASP.Net项目中的Web API方法访问ASP.Net数据缓存

[英]Access ASP.Net Data Cache from a Web API method in same ASP.Net project

I need to remove ASP.Net cache from inside a Web API method. 我需要从Web API方法中删除ASP.Net缓存。 This cache by the name of 'ContentNames' was set in the code-behind of an aspx page using following code. 使用以下代码在aspx页面的代码后面设置了名为“ ContentNames”的缓存。 Is this possible, and if yes, then how would I access ASP.Net data cache from inside the Web API method? 这是否可能,如果可以,我将如何从Web API方法内部访问ASP.Net数据缓存?

The Web API and all the aspx pages are part of the same website project in Visual Studio 2013. Web API和所有aspx页面是Visual Studio 2013中同一网站项目的一部分。

System.Web.HttpContext.Current.Cache.Insert("ContentNames", dt, null,
      System.Web.Caching.Cache.NoAbsoluteExpiration, new TimeSpan(0, 60, 0));

The Web API method from where I need to access and remove 'ContentNames' data cache, looks like below. 我需要从中访问和删除“ ContentNames”数据缓存的Web API方法如下所示。

    [Authorize]
    [HttpPut]
    public HttpResponseMessage ApproveOrRejectContent( RadEditorContentAdminParas paras)
    {

         var data =  GetUnApprovedContent(paras.ApprovedOrRejected, paras.PageId);

          //NEED to remove a Cache by the name of 'ContentNames' ???

        return Request.CreateResponse<ContentsInfoResult>(HttpStatusCode.OK, data);
    }

只需将System.Web的引用添加到Web Api控制器,就可以访问Current缓存并将其删除:

System.Web.HttpContext.Current.Cache.Remove("ContentNames"); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM