1.Cache对象支持清扫(scavenging):当系统资源不足时,它会自动从缓存中删除低优先级的或不常用的项。 2.在从缓存中获取一个项后,应当检查看该项是否为nothing。如果为nothing,就需要把该项重新赋值给缓存。 3.在添加一个项到缓存中时,可以把该项与一个文件关联。如果文件发生变化,则该项被自动从缓存中删除:Cache.Insert("itemName","itemValue!",New CacheDependency(MapPath("fileName.txt"))) 4.设置缓存依赖,当数据库数据发生变化时,清除缓存中相应的项: 1.首先创建一个触发器: CREATE TRIGGER UpdateCache ON Products FOR UPDATE, DELETE, INSERT AS DECLARE @cmd Varchar( 200 ) SELECT @cmd = ''''echo '''' + Cast( getDATE() As Varchar( 50 ) ) + '''' > c:\dataTableChange.txt'''' EXEC master..xp_cmdshell @cmd, no_output 2.测试页面 <%@ Import Namespace="System.Data" %> <%@ Import Namespace="System.Data.SqlClient" %> <Script Runat="Server"> Sub Page_Load Dim dstProducts As DataSet dstProducts = Cache( "productsDS" ) If dstProducts Is Nothing Then dstProducts = GetProducts() Cache.Insert( "Products", dstProducts, _ New CacheDependency( "c:\dataTableChange.txt" ) ) End If dgrdProducts.DataSource = dstProducts dgrdProducts.DataBind() End Sub Function GetProducts() As DataSet Dim conNorthwind As SqlConnection Dim strSelect As String Dim dadProducts As SqlDataAdapter Dim dstProducts As DataSet conNorthwind = New SqlConnection( "Server=Localhost;UID=sa;PWD=XXXXXX;Database=Northwind" ) strSelect = "Select TOP 10 * From Products ORDER BY ProductID" dadProducts = New SqlDataAdapter( strSelect, conNorthwind ) dstProducts = New DataSet() dadProducts.Fill( dstProducts, "ProductsDS" ) Return dstProducts End Function </Script> <html> <head><title>test.aspx</title> </head> <body> <asp:DataGrid ID="dgrdProducts" Runat="Server" /> </body> </html> 注:该方法调用xp_cmdshell存储过程来完成该功能,则需要赋予访问者管理员权限,安全性差。慎用!
[C语言系列]NET 中C#的switch语句的语法 [系统软件]托拽Explore中的文件到VB.net的窗口 [系统软件]XPDL学习笔记 [系统软件]Boost库在XP+Visual C++.net中的安装 [常用软件]新配色面板:Paint.Net3.0RC1官方下载 [常用软件]用内建的“Net Meeting”聊天 [VB.NET程序]Henry的VB.NET之旅(三)—共享成员 [VB.NET程序]Henry的VB.NET之旅(二)—构造与析构 [VB.NET程序]Henry的VB.NET之旅(一)—失踪的窗体 [VB.NET程序]在托盘上显示Balloon Tooltip(VB.NET)
|