文章拍的电视剧有哪些:缓存相关的操作类--System.Web.Caching无效

来源:百度文库 编辑:查人人中国名人网 时间:2024/05/06 13:59:05
NET2003-C#环境报错显示类型或命名空间名称“Caching”在类或命名空间“System.Web”中不存在(是否缺少程序集引用?)。
System.Web后面就是点不出任何东西来!
请高手指点一下。谢谢!

AggregateCacheDependency 类监视依赖项对象的集合,以便在任何依赖项对象更改时,该缓存项都会自动移除。数组中的对象可以是 CacheDependency 对象、SqlCacheDependency 对象、从 CacheDependency 派生的自定义对象或这些对象的任意组合。

AggregateCacheDependency 类与 CacheDependency 类的不同之处在于前者允许您将不同类型的多个依赖项与单个缓存项关联。例如,如果您创建一个从 SQL Server 数据库表和 XML 文件导入数据的页,则可创建一个 SqlCacheDependency 对象来表示数据库表的依赖项,以及一个 CacheDependency 来表示 XML 文件的依赖项。可创建 AggregateCacheDependency 类的一个实例,将每个依赖项添加到该类中,而不是为每个依赖项调用 Cache.Insert 方法。然后,可使用单个 Insert 调用使该页依赖于 AggregateCacheDependency 实例。

下面的代码示例使用 AggregateCacheDependency 类将名为 XMLDataSet 的 DataSet 添加到依赖于文本文件和 XML 文件的缓存中。

' When the page is loaded, use the
' AggregateCacheDependency class to make
' a cached item dependent on two files.

Sub Page_Load(sender As Object, e As EventArgs)
Dim Source As DataView

Source = Cache("XMLDataSet")

If Source Is Nothing
Dim DS As New DataSet
Dim FS As FileStream
Dim Reader As StreamReader
Dim txtDep As CacheDependency
Dim xmlDep As CacheDependency
Dim aggDep As AggregateCacheDependency

FS = New FileStream(Server.MapPath("authors.xml"),FileMode.Open,FileAccess.Read)
Reader = New StreamReader(FS)
DS.ReadXml(Reader)
FS.Close()

Source = new DataView(ds.Tables(0))
' Create two CacheDependency objects, one to a
' text file and the other to an XML file.
' Create a CacheDependency array with these
' two objects as items in the array.
txtDep = New CacheDependency(Server.MapPath("Storage.txt"))
xmlDep = New CacheDependency(Server.MapPath("authors.xml"))
Dim DepArray() As CacheDependency = {txtDep, xmlDep}

' Create an AggregateCacheDependency object and
' use the Add method to add the array to it.
aggDep = New AggregateCacheDependency()
aggDep.Add(DepArray)

' Call the GetUniqueId method to generate
' an ID for each dependency in the array.
msg1.Text = aggDep.GetUniqueId()

' Add the new data set to the cache with
' dependencies on both files in the array.
Cache.Insert("XMLDataSet", Source, aggDep)
If aggDep.HasChanged = True Then
chngMsg.Text = "The dependency changed at: " & DateTime.Now

Else
chngMsg.Text = "The dependency changed last at: " & aggDep.UtcLastModified.ToString()
End If

cacheMsg1.Text = "Dataset created explicitly"
Else
cacheMsg1.Text = "Dataset retrieved from cache"
End If

MyLiteral.Text = Source.Table.TableName
MyDataGrid.DataSource = Source
MyDataGrid.DataBind()
End Sub

Public Sub btn_Click(sender As Object, e As EventArgs )

If (MyTextBox.Text = String.Empty) Then
msg2.Text ="You have not changed the text file."
Else
msg2.Text="You added " & MyTextBox.Text & "."

' Create an instance of the StreamWriter class
' to write text to a file.
Dim sw As StreamWriter
sw = File.CreateText(Server.MapPath("Storage.txt"))

' Add some text to the file.
sw.Write("You entered:")
sw.WriteLine(MyTextBox.Text)

' Write arbitrary objects to the file as needed.
sw.Write("Text added at:")
sw.WriteLine(DateTime.Now)
sw.WriteLine("-------------------")
sw.Close()
End If
End Sub