有谁用过.net+cache数据库的,可否有例子瞧瞧,谢谢先!

解决方案 »

  1.   

    创建一个绝对过期策略例子:<%@ 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,  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>
      

  2.   

    # region 论坛首页类别和板块数据
    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
      

  3.   

    cache是在医疗行业用的很广泛的数据库,据说它比别的数据库要快5倍多,但用vb开发它比较多点,好象用.net技术开发的没见到过!