System.Web.Caching.OutputCache.GetProvider C# (CSharp) Method

GetProvider() static private method

static private GetProvider ( string providerName ) : System.Web.Caching.OutputCacheProvider
providerName string
return System.Web.Caching.OutputCacheProvider
		internal static OutputCacheProvider GetProvider (string providerName)
		{
			if (String.IsNullOrEmpty (providerName))
				return null;

			if (String.Compare (providerName, DEFAULT_PROVIDER_NAME, StringComparison.Ordinal) == 0)
				return DefaultProvider;

			OutputCacheProviderCollection providers = OutputCache.Providers;
			return (providers != null ? providers [providerName] : null);
		}
		

Usage Example

        OutputCacheProvider FindCacheProvider(HttpApplication app)
        {
            HttpContext ctx = HttpContext.Current;

            if (app == null)
            {
                app = ctx != null ? ctx.ApplicationInstance : null;

                if (app == null)
                {
                    throw new InvalidOperationException("Unable to find output cache provider.");
                }
            }

            string providerName = app.GetOutputCacheProviderName(ctx);

            if (String.IsNullOrEmpty(providerName))
            {
                throw new ProviderException("Invalid OutputCacheProvider name. Name must not be null or an empty string.");
            }

            OutputCacheProvider ret = OutputCache.GetProvider(providerName);

            if (ret == null)
            {
                throw new ProviderException(String.Format("OutputCacheProvider named '{0}' cannot be found.", providerName));
            }

            return(ret);
        }