CacheDependency.HasChanged Property

Definition

Gets a value indicating whether the CacheDependency object has changed.

C#
public bool HasChanged { get; }

Property Value

true if the CacheDependency object has changed; otherwise, false. The default is false.

Examples

The following code example demonstrates using the HasChanged property to determine whether a CacheDependency changed since the previous request for an item in the Cache. The dt value passed in the start parameter is set to DateTime.Now.

C#
// Insert the cache item.
CacheDependency dep = new CacheDependency(fileName, dt);
cache.Insert("key", "value", dep);

// Check whether CacheDependency.HasChanged is true.
if (dep.HasChanged)
  Response.Write("<p>The dependency has changed.");  
else Response.Write("<p>The dependency has not changed.");

Remarks

You can add an item to an ASP.NET application's Cache with a CacheDependency. When the CacheDependency changes, the item added to the Cache is invalidated and removed from the cache. You can use this property to determine whether a CacheDependency has changed, and recreate the item in the Cache if that has occurred.

Applies to

Product Versions
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

See also