给出的通用处理器:ASP.net缓存ASHX文件服务器端
<%@ WebHandler Language="C#" Class="autocomp" %>
using System;
using System.Text;
using System.Text.RegularExpressions;
using System.Web;
using System.Web.UI;
public class autocomp : IHttpHandler {
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "application/json";
context.Response.BufferOutput = true;
var searchTerm = (context.Request.QueryString["name_startsWith"] + "").Trim();
context.Response.Write(searchTerm);
context.Response.Write(DateTime.Now.ToString("s"));
context.Response.Flush();
}
public bool IsReusable {
get {
return false;
}
}
}
我怎么会server side
缓存文件1小时基础上,name_startsWith
查询字符串参数?随着网络用户控制它很简单:
<%@ OutputCache Duration="120" VaryByParam="paramName" %>
但我一直在寻找了一段时间做同样的与通用处理器(ashx
)文件并不能找到任何解决方案。
你会在客户端上使用[这个东西(缓存http://stackoverflow.com/questions/1109768/how-to-use-output-caching-on -ashx-handler),然后在您要获取数据时使用HttpContext.Cache将实际数据用于服务器端缓存。但是你不能为此使用任何类型的输出缓存。此外,请记住确保您的HttpContext.Cache代码是线程安全的。 ;) – Tombala
在下面编辑我的答案以回答对帖子的更改。 –