AggregateCacheDependency AggregateCacheDependency AggregateCacheDependency AggregateCacheDependency Class

Définition

Combine plusieurs dépendances entre un élément stocké dans un tableau d’objets CacheDependency et l’objet Cache d’une application ASP.NET.Combines multiple dependencies between an item stored in an ASP.NET application's Cache object and an array of CacheDependency objects. Cette classe ne peut pas être héritée.This class cannot be inherited.

public ref class AggregateCacheDependency sealed : System::Web::Caching::CacheDependency
public sealed class AggregateCacheDependency : System.Web.Caching.CacheDependency
type AggregateCacheDependency = class
    inherit CacheDependency
Public NotInheritable Class AggregateCacheDependency
Inherits CacheDependency
Héritage
AggregateCacheDependencyAggregateCacheDependencyAggregateCacheDependencyAggregateCacheDependency

Exemples

Le code suivant exemple utilise le AggregateCacheDependency classe pour ajouter un DataSet, nommé XMLDataSet, dans le cache est dépendant d’un fichier texte et un fichier XML.The following code example uses the AggregateCacheDependency class to add a DataSet, named XMLDataSet, to the cache that is dependent on a text file and an XML file.

' 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

Remarques

Le AggregateCacheDependency classe surveille une collection d’objets de dépendance afin que lorsqu’une d’elles change, l’élément mis en cache est automatiquement supprimé.The AggregateCacheDependency class monitors a collection of dependency objects so that when any of them change, the cached item is automatically removed. Les objets dans le tableau peuvent être CacheDependency objets, SqlCacheDependency objets, des objets personnalisés dérivés de CacheDependency, ou toute combinaison de ceux-ci.The objects in the array can be CacheDependency objects, SqlCacheDependency objects, custom objects derived from CacheDependency, or any combination of these.

Le AggregateCacheDependency classe diffère de la CacheDependency classe car elle permet d’associer plusieurs dépendances de types différents à un seul élément mis en cache.The AggregateCacheDependency class differs from the CacheDependency class in that it allows you to associate multiple dependencies of different types with a single cached item. Par exemple, si vous créez une page qui importe des données à partir d’une table de base de données SQL Server et un fichier XML, vous pouvez créer un SqlCacheDependency objet pour représenter une dépendance sur la table de base de données et un CacheDependency pour représenter la dépendance sur le fichier XML.For example, if you create a page that imports data from a SQL Server database table and an XML file, you can create a SqlCacheDependency object to represent a dependency on the database table and a CacheDependency to represent the dependency on the XML file. Au lieu de fabriquer une Cache.Insert appel de méthode pour chaque dépendance, vous pouvez créer une instance de la AggregateCacheDependency classe avec chaque dépendance est ajoutée.Rather than making an Cache.Insert method call for each dependency, you can create an instance of the AggregateCacheDependency class with each dependency added to it. Vous pouvez ensuite utiliser un seul Insert appel à faire de la page dépend de la AggregateCacheDependency instance.You can then use a single Insert call to make the page dependent on the AggregateCacheDependency instance.

Constructeurs

AggregateCacheDependency() AggregateCacheDependency() AggregateCacheDependency() AggregateCacheDependency()

Initialise une nouvelle instance de la classe AggregateCacheDependency.Initializes a new instance of the AggregateCacheDependency class.

Méthodes

Add(CacheDependency[]) Add(CacheDependency[]) Add(CacheDependency[]) Add(CacheDependency[])

Ajoute un tableau d'objets CacheDependency à l'objet AggregateCacheDependency.Adds an array of CacheDependency objects to the AggregateCacheDependency object.

DependencyDispose() DependencyDispose() DependencyDispose() DependencyDispose()

Libère les ressources utilisées par la classe CacheDependency et toutes classes qui dérivent de CacheDependency.Releases the resources used by the CacheDependency class and any classes that derive from CacheDependency.

(Inherited from CacheDependency)
Dispose() Dispose() Dispose() Dispose()

Libère les ressources utilisées par l'objet CacheDependency.Releases the resources used by the CacheDependency object.

(Inherited from CacheDependency)
Equals(Object) Equals(Object) Equals(Object) Equals(Object)

Détermine si l'objet spécifié est identique à l'objet actuel.Determines whether the specified object is equal to the current object.

(Inherited from Object)
FinishInit() FinishInit() FinishInit() FinishInit()

Termine l'initialisation de l'objet CacheDependency.Completes initialization of the CacheDependency object.

(Inherited from CacheDependency)
GetFileDependencies() GetFileDependencies() GetFileDependencies() GetFileDependencies()

Obtient les dépendances de fichier.Gets the file dependencies.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

Fait office de fonction de hachage par défaut.Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

Obtient le Type de l'instance actuelle.Gets the Type of the current instance.

(Inherited from Object)
GetUniqueID() GetUniqueID() GetUniqueID() GetUniqueID()

Récupère un identificateur unique pour l'objet AggregateCacheDependency.Retrieves a unique identifier for the AggregateCacheDependency object.

ItemRemoved() ItemRemoved() ItemRemoved() ItemRemoved()

Appelé lorsqu’une entrée de cache surveillée est supprimée.Called when a monitored cache entry is removed.

(Inherited from CacheDependency)
KeepDependenciesAlive() KeepDependenciesAlive() KeepDependenciesAlive() KeepDependenciesAlive()

Met à jour l’heure du dernier accès de chaque élément de cache qui dépend de cet élément.Updates the last access time of every cache item that depends on this item.

(Inherited from CacheDependency)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

Crée une copie superficielle du Object actuel.Creates a shallow copy of the current Object.

(Inherited from Object)
NotifyDependencyChanged(Object, EventArgs) NotifyDependencyChanged(Object, EventArgs) NotifyDependencyChanged(Object, EventArgs) NotifyDependencyChanged(Object, EventArgs)

Avertit l'objet CacheDependency de base que la dépendance représentée par une classe CacheDependency dérivée a changé.Notifies the base CacheDependency object that the dependency represented by a derived CacheDependency class has changed.

(Inherited from CacheDependency)
SetCacheDependencyChanged(Action<Object,EventArgs>) SetCacheDependencyChanged(Action<Object,EventArgs>) SetCacheDependencyChanged(Action<Object,EventArgs>) SetCacheDependencyChanged(Action<Object,EventArgs>)

Ajoute une méthode d’action pour notifier les parties intéressées par les modifications apportées à cette dépendance.Adds an Action method to handle notifying interested party in changes to this dependency.

(Inherited from CacheDependency)
SetUtcLastModified(DateTime) SetUtcLastModified(DateTime) SetUtcLastModified(DateTime) SetUtcLastModified(DateTime)

Marque l'heure de la dernière modification d'une dépendance.Marks the time when a dependency last changed.

(Inherited from CacheDependency)
TakeOwnership() TakeOwnership() TakeOwnership() TakeOwnership()

Permet au premier utilisateur de déclarer la propriété exclusive de cette dépendance.Allows the first user to declare exclusive ownership of this dependency.

(Inherited from CacheDependency)
ToString() ToString() ToString() ToString()

Retourne une chaîne qui représente l'objet actuel.Returns a string that represents the current object.

(Inherited from Object)

Propriétés

HasChanged HasChanged HasChanged HasChanged

Obtient une valeur indiquant si l'objet CacheDependency a changé.Gets a value indicating whether the CacheDependency object has changed.

(Inherited from CacheDependency)
UtcLastModified UtcLastModified UtcLastModified UtcLastModified

Obtient l'heure de la dernière modification de la dépendance.Gets the time when the dependency was last changed.

(Inherited from CacheDependency)

S’applique à