有谁用过.net+cache数据库的,可否有例子瞧瞧,谢谢先!
解决方案 »
- 关于空间选择和数据绑定的问题
- 求一解决方案,是关于2个服务器之间上传数据的
- 服务器上已经放了使用水晶报表的asp.net 程序,但是浏览时有错,请问是不是一定要在服务上安装水晶报表或者安装vs.net2003 才能ok的?
- 难度高的问题(关于DataGrid以及DataSet和数据库的问题)
- 请问一下,怎么样动太生成水晶报表啊?
- 模板列赋值无效,请高手帮我看看
- 关于网站初期建设的数据库设计
- 谁有好的 GridView Skin?
- 高分求救,急:用javascript弹出关闭警告框问题!!!
- 创建项目问题 ——小问题
- 100求,为什么我的用户控件只能在同一级目录引用,在线等候
- 两层显示的问题?大家快来帮忙呀!
<script language="C#" runat=server>void Page_Load(Object sender , EventArgs e)
{
string strTime;
{
strTime = DateTime.Now.ToString( "T" );
Cache.Insert("Time", strTime, null, DateTime.Now.AddMinutes( 1 ), Cache.NoSlidingExpiration );
}
lblMessage.Text = strTime;
}</Script><html>
<head><title>AbsoluteExpiration.aspx</title></head>
<body>Data last cached:
<asp:Label
ID="lblMessage"
Font-Bold="True"
ForeColor="Blue"
Runat="Server" /></body>
</html>创建一个相对过期策略例子:<%@ Page Language="C#" %>
<script language="C#" runat=server>void Page_Load(Object sender , EventArgs e)
{
string strTime;
{
strTime = DateTime.Now.ToString( "T" );
Cache.Insert("Time", strTime, null, Cache.NoAbsoluteExpiration, TimeSpan.FromMinutes( 1 ) );
}
lblMessage.Text = strTime;
}
</Script><html>
<head><title>DataSlide.aspx</title></head>
<body>Data last cached:
<asp:Label
ID="lblMessage"
Font-Bold="True"
ForeColor="Blue"
Runat="Server" /></body>
</html>创建一个缓存回调方法例子:<%@ Page Language="C#" %>
<script language="C#" runat=server>public static CacheItemRemovedCallback onRemove;void ItemRemoved( string strItemKey, object objItemValue, CacheItemRemovedReason objRemovedReason )
{
string strLogEntry; strLogEntry = "Item with value " + objItemValue.ToString() ;
strLogEntry = " removed at " + System.DateTime.Now.ToString( "T" );
strLogEntry = " because of " + objRemovedReason.ToString();
if ( Application[ "CacheLog" ] == null )
{
Application[ "CacheLog" ] = new ArrayList();
}
//Application[ "CacheLog" ].Add( "strLogEntry" );
//Beep();
}void btnAddCache_Click( object s, EventArgs e )
{
onRemove = new CacheItemRemovedCallback( ItemRemoved );
Cache.Insert( "myItem", txtNewValue.Text, null, DateTime.Now.AddSeconds( 10 ), Cache.NoSlidingExpiration, CacheItemPriority.High, onRemove );
}void btnRemoveCache_Click( object s, EventArgs e )
{
Cache.Remove( "myItem" );
}void Page_PreRender( object s, EventArgs e )
{
dgrdCacheLog.DataSource = Application[ "CacheLog" ];
dgrdCacheLog.DataBind();
}
</Script><html>
<head><title>CacheCallback.aspx</title></head>
<body>
<form Runat="Server"><h2>Cache Log</h2>
<asp:DataGrid
ID="dgrdCacheLog"
CellPadding="8"
Runat="Server" />
<p>
<asp:TextBox
id="txtNewValue"
Runat="Server" />
<p>
<asp:Button
id="btnAddCache"
Text="Add To Cache!"
OnClick="btnAddCache_Click"
Runat="Server" /><asp:Button
id="btnRemoveCache"
Text="Remove From Cache!"
OnClick="btnRemoveCache_Click"
Runat="Server" /><asp:Button
Text="Refresh Page!"
Runat="Server" /></form>
</body>
</html>
public static DataSet GetClassAndBoard()
{
if(System.Web.HttpContext.Current.Cache["ClassAndBoard"]==null)
{
DataSet ds=new DataSet();
SqlHelper.FillDataset(Conn.strconn,CommandType.StoredProcedure,"sp_SelectClass",ds,new string[]{"tb_class"});
SqlHelper.FillDataset(Conn.strconn,CommandType.StoredProcedure,"sp_SelectBoard",ds,new string[]{"tb_board"});
ds.Relations.Add("Board_Class",ds.Tables["tb_class"].Columns["Class_ID"],ds.Tables["tb_board"].Columns["Board_Class_ID"]);
System.Web.HttpContext.Current.Cache["ClassAndBoard"]=ds;
return ds;
}
else
{
return (DataSet)System.Web.HttpContext.Current.Cache["ClassAndBoard"];
}
}
# endregion