Jquery 如何将AJAX Json数据缓存5分钟?
我能够缓存AJAX数据结果,但无法指定缓存时间。 以下是部分代码:Jquery 如何将AJAX Json数据缓存5分钟?,jquery,wcf,caching,Jquery,Wcf,Caching,我能够缓存AJAX数据结果,但无法指定缓存时间。 以下是部分代码: [OperationContract(Name = "Prepopulate_GetData")] [WebGet(UriTemplate = "/Prepopulate/GetData", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)] string GetData(); Client call: functio
[OperationContract(Name = "Prepopulate_GetData")]
[WebGet(UriTemplate = "/Prepopulate/GetData", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
string GetData();
Client call:
function GetData() {
$.ajax
({
url: "svc/Prepopulate.svc/Prepopulate/GetData"
, cache: true
...
注意:我无法使用AspNetCacheProfile属性,因为此web应用程序中仍使用.NET3.5。该属性仅适用于.Net 4.0>
我也在WCF中尝试了下面的代码,但没有成功:
System.Web.HttpContext.Current.Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1));
System.Web.HttpContext.Current.Response.Cache.SetCacheability(System.Web.HttpCacheability.Private);
System.Web.HttpContext.Current.Response.Cache.SetNoStore();
有什么想法吗?
谢谢你你有-1,这意味着在创建时过期,也删除了SetNoStore,你会尝试:System.Web.HttpContext.Current.Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(5));System.Web.HttpContext.Current.Response.Cache.SetCacheability(System.Web.HttpCacheability.Private);如果你把我的回答作为答案而不是投票的话,那就太好了。。。