Export (0) Print
Expand All

CacheDependency Constructor

.NET Framework 1.1

Initializes a new instance of the CacheDependency class.

Overload List

Initializes a new instance of the CacheDependency class that monitors a file or directory for changes.

[Visual Basic] Public Sub New(String)
[C#] public CacheDependency(string);
[C++] public: CacheDependency(String*);
[JScript] public function CacheDependency(String);

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

[Visual Basic] Public Sub New(String())
[C#] public CacheDependency(string[]);
[C++] public: CacheDependency(String*[]);
[JScript] public function CacheDependency(String[]);

Initializes a new instance of the CacheDependency class that monitors a file or directory for changes and indicates when change tracking is to begin.

[Visual Basic] Public Sub New(String, DateTime)
[C#] public CacheDependency(string, DateTime);
[C++] public: CacheDependency(String*, DateTime);
[JScript] public function CacheDependency(String, DateTime);

Initializes a new instance of the CacheDependency class that monitors an array of file paths (to files or directories) for changes and specifies a time when change monitoring begins.

[Visual Basic] Public Sub New(String(), DateTime)
[C#] public CacheDependency(string[], DateTime);
[C++] public: CacheDependency(String*[], DateTime);
[JScript] public function CacheDependency(String[], DateTime);

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

[Visual Basic] Public Sub New(String(), String())
[C#] public CacheDependency(string[], string[]);
[C++] public: CacheDependency(String*[], String*[]);
[JScript] public function CacheDependency(String[], String[]);

Initializes a new instance of the CacheDependency class that monitors an array of file paths (to files or directories), an array of cache keys, or both for changes. It also makes itself dependent upon a separate instance of the CacheDependency class.

[Visual Basic] Public Sub New(String(), String(), CacheDependency)
[C#] public CacheDependency(string[], string[], CacheDependency);
[C++] public: CacheDependency(String*[], String*[], CacheDependency*);
[JScript] public function CacheDependency(String[], String[], CacheDependency);

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

[Visual Basic] Public Sub New(String(), String(), DateTime)
[C#] public CacheDependency(string[], string[], DateTime);
[C++] public: CacheDependency(String*[], String*[], DateTime);
[JScript] public function CacheDependency(String[], String[], DateTime);

Initializes a new instance of the CacheDependency class that monitors an array of file paths (to files or directories), an array of cache keys, or both for changes. It also makes itself dependent upon another instance of the CacheDependency class and a time when the change monitoring begins.

[Visual Basic] Public Sub New(String(), String(), CacheDependency, DateTime)
[C#] public CacheDependency(string[], string[], CacheDependency, DateTime);
[C++] public: CacheDependency(String*[], String*[], CacheDependency*, DateTime);
[JScript] public function CacheDependency(String[], String[], CacheDependency, DateTime);

Example

[Visual Basic, C#] The following example creates a CreateDependency method. When this method is called, it creates a DateTime object and the Cache.Item property is used to add an item to the cache with a key parameter of key1 and a value of Value 1. An array of strings, dependencyKey, is then created with the value of key1 as well. Another CacheDependency constructor creates a CacheDependency object, dep1, that passes dependencyKey as a parameter argument. A second CacheDependency object, dep2, is created using this constructor, with dep1 and the DateTime object passed as parameter arguments. This second dependency is dependent on the first and dependency monitoring will begin ten seconds after the CreateDependency method is called. The Cache.Insert method is called next, using the second CacheDependency object as a parameter. If the first dependency changes in any way, the cached item will be invalidated.

[Visual Basic, C#] Note   This example shows how to use one of the overloaded versions of the CacheDependency constructor. For other examples that might be available, see the individual overload topics.
[Visual Basic] 
Public Sub CreateDependency(sender As [Object], e As EventArgs)
  ' Create a DateTime object.
  Dim dt as DateTime = DateTime.Now.AddSeconds(10)        

  ' Create a cache entry.
  Cache("key1") = "Value 1"
   
  ' Make key2 dependent on key1 using double dependency.
  Dim dependencyKey(0) As [String]
  dependencyKey(0) = "key1"
  Dim dep1 As New CacheDependency(Nothing, dependencyKey)
   
  ' Make a second CacheDependency dependent on dep1
  ' and use dt to start change monitoring.        
  Dim dep2 As New CacheDependency(Nothing, Nothing, dep1, dt)
   
  Cache.Insert("key2", "Value 2", dep2)
   
  DisplayValues()
   End Sub 'CreateDependency

[C#] 
public void CreateDependency(Object sender, EventArgs e) {
    // Create a DateTime object.
    DateTime dt = DateTime.Now.AddSeconds(10);

    // Create a cache entry.
    Cache["key1"] = "Value 1";

    // Make key2 dependent on key1.
    String[] dependencyKey = new String[1];
    dependencyKey[0] = "key1";
    CacheDependency dep1 = new CacheDependency(null, dependencyKey);

    // Make a second CacheDependency dependent on dep1.
    // and use dt to start change monitoring.        
    CacheDependency dep2 = new CacheDependency(null, null, dep1, dt);

    Cache.Insert("key2", "Value 2", dep2);

    DisplayValues();
}

[C++, JScript] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button Language Filter in the upper-left corner of the page.

See Also

CacheDependency Class | CacheDependency Members | System.Web.Caching Namespace

Show:
© 2014 Microsoft