Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

DataSourceCacheDurationConverter Class

Provides a type converter to convert 32-bit signed integer objects to and from data source control cache duration representations.

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

[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public class DataSourceCacheDurationConverter : Int32Converter

ASP.NET data source controls that support caching typically provide a CacheDuration property that you can set to the number of seconds that the control caches data. The value 0 represents "Infinite" in these caching contexts, and the DataSourceCacheDurationConverter class takes care of this explicit conversion.

Page developers do not use the DataSourceCacheDurationConverter class. Control developers who are developing data source controls that support caching use this type converter along with the TypeConverterAttribute attribute to decorate a property that represents a cache duration setting of a custom data source control.

The following code example demonstrates how you can decorate a property on a data source control that supports caching with a TypeConverterAttribute attribute. In this example, the data source control supports caching semantics and exposes three properties modeled after other ASP.NET data source controls: EnableCaching, CacheDuration, and CacheExpirationPolicy. The CacheDuration property uses the DataSourceCacheDurationConverter type converter.

using System;
using System.ComponentModel;
using System.Web.UI;

[ NonVisualControl() ]
public class SomeDataSource : DataSourceControl
{
    // Implementation of a custom data source control. 

    // The SdsCache object is an imaginary cache object 
    // provided for this example. It has not actual  
    // implementation. 
    private SdsCache m_sdsCache = new SdsCache();
    internal SdsCache Cache {
        get { return m_sdsCache; }
    }

    [TypeConverterAttribute(typeof(DataSourceCacheDurationConverter))]
    public int CacheDuration {
        get { return Cache.Duration; }
    }

    public DataSourceCacheExpiry CacheExpirationPolicy {
        get { return Cache.Expiry; }
        set { Cache.Expiry = value; }
    }

    public bool EnableCaching {
        get { return Cache.Enabled; }
        set { Cache.Enabled = value; }
    }

    protected override DataSourceView GetView(string viewName)
    {
        throw new Exception("The method or operation is not implemented.");
    }

    // ...
}

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

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

.NET Framework

Supported in: 3.5, 3.0, 2.0

Community Additions

ADD
Show:
© 2015 Microsoft