CacheDependency Constructor (String[])

 

Initializes a new instance of the CacheDependency class that monitors an array of paths (to files or directories) for changes.

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

public CacheDependency(
	string[] filenames
)

Parameters

filenames
Type: System.String[]

An array of paths (to files or directories) that the cached object is dependent upon. When any of these resources changes, the cached object becomes obsolete and is removed from the cache.

If any of the files or directories in the array changes or is removed from the array, the cached item becomes obsolete and is removed from the application's Cache object.

Also, if any of the directories or files specified in the filenames parameter is not found in the file system, it is treated as missing. If a directory or file is missing when the object with the dependency is added to the Cache, the cached object will be removed from the Cache when that directory or file is created.

For example, assume that you add an object to the Cache with a dependency on the following file path: c:\stocks\xyz.dat. If that file is not found when the CacheDependency object is created, but is created later, the cached object is removed upon the creation of the xyz.dat file.

System_CAPS_noteNote

When you create the array that contains the file dependencies, you must define the number of files that the item you are adding to the Cache is dependent on.

The following code example demonstrates how to use the Cache.Insert method to add an item to the Cache with dependencies on an array of files. You can also make the item dependent on an array of directories.

    // Make key1 dependent on several files.
    String[] files = new String[2];
    files[0] = Server.MapPath("isbn.xml");
    files[1] = Server.MapPath("customer.xml");
    CacheDependency dependency = new CacheDependency(files);

    Cache.Insert("key1", "Value 1", dependency);
}

.NET Framework
Available since 1.1
Return to top
Show: