OutputCacheProvider FindCacheProvider (HttpApplication app) { #if NET_4_0 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; #else if (provider == null) provider = new InMemoryOutputCacheProvider (); return provider; #endif }
OutputCacheProvider FindCacheProvider (HttpApplication app) { #if NET_4_0 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."); if (String.Compare (providerName, OutputCache.DEFAULT_PROVIDER_NAME, StringComparison.Ordinal) == 0) { if (provider == null) provider = new InMemoryOutputCacheProvider (); return provider; } OutputCacheProviderCollection providers = OutputCache.Providers; OutputCacheProvider ret = providers != null ? providers [providerName] : null; if (ret == null) throw new ProviderException (String.Format ("OutputCacheProvider named '{0}' cannot be found.", providerName)); return ret; #else if (provider == null) provider = new InMemoryOutputCacheProvider (); return provider; #endif }
public void GetOutputCacheProviderName () { var app = new HttpApplication (); Assert.AreEqual ("AspNetInternalProvider", app.GetOutputCacheProviderName (null), "#A1"); }