This documentation is archived and is not being maintained.

CacheDependency.GetUniqueID Method

Retrieves a unique identifier for a CacheDependency object.

Namespace:  System.Web.Caching
Assembly:  System.Web (in System.Web.dll)

public virtual string GetUniqueID()

Return Value

Type: System.String
The unique identifier for the CacheDependency object.

This method can be particularly useful for tracking multiple instances of the CacheDependency class associated with an item or an application.

The identifier is a combination of either the file name (for a file dependency) or the key name (for a cache-key dependency) and a string that this method assigns to the dependency. In classes that derive from the CacheDependency class, you can override this method to customize how it generates the unique identifier.

The following code example creates an AggregateCacheDependency object, named aggDep, with two CacheDependency objects in its array. Once aggDep is instantiated, the code calls the GetUniqueID method to generate a unique identifier for both dependencies that aggDep contains and displays the identifiers to the containing page. An item is then added to the Cache, using the Cache.Insert method, with aggDep as a dependency.

' 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()

 ' 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)

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.