62,254
社区成员
发帖
与我相关
我的任务
分享
<%@ Page Language="C#" %>
<script runat="server">
void Button1_Click1(object sender, EventArgs e)
{
Cache["bb时间戳"] = DateTime.Now.ToString();
}
string Get1234()
{
string key = "sp1234's SQL query";
string x = Cache[key] as string;
if (x == null)
{
x = DateTime.Now.ToString();
Cache["bb时间戳"] = DateTime.Now.ToString();
Cache.Insert(key, x, new CacheDependency(new string[] { }, new string[] { "bb时间戳" }));
}
return x;
}
</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click1" Text="Button" />
<br />
<% = Get1234() %>
<br />
<asp:Button ID="Button2" runat="server" Text="Button" />
</form>
</body>
</html>
<%@ Page Language="C#" %>
<script runat="server">
void Button1_Click1(object sender, EventArgs e)
{
Cache["bb时间戳"] = DateTime.Now.ToString();
}
</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click1" Text="Button" />
</form>
</body>
</html>
<%@ Page Language="C#" %>
<%@ OutputCache Duration="6000" VaryByParam="*" VaryByCustom="CacheBy:aa标记,bb时间戳" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<% =DateTime.Now.ToString() %>
</div>
</form>
</body>
</html>
public override string GetVaryByCustomString(HttpContext context, string custom)
{
if (custom.StartsWith("CacheBy:"))
{
var ss = string.Empty;
foreach (string s in custom.Substring(8).Split(','))
{
string xx = context.Cache[s] as string;
ss += (xx == null ? string.Empty : xx);
}
return ss;
}
}