void RetrieveCachedContents() { cacheKey = CreateKey(); OutputCacheProvider provider = GetProvider(); cachedData = provider.Get(cacheKey) as string; }
public static void RemoveOutputCacheItem(string path) { if (path == null) { throw new ArgumentNullException("path"); } if (path.Length == 0) { return; } if (path [0] != '/') { throw new ArgumentException("'" + path + "' is not an absolute virtual path."); } #if NET_4_0 RemoveOutputCacheItem(path, OutputCache.DefaultProviderName); #else HttpContext context = HttpContext.Current; HttpApplication app_instance = context != null ? context.ApplicationInstance : null; HttpModuleCollection modules = app_instance != null ? app_instance.Modules : null; OutputCacheModule ocm = modules != null?modules.Get("OutputCache") as OutputCacheModule : null; OutputCacheProvider internalProvider = ocm != null ? ocm.InternalProvider : null; if (internalProvider == null) { return; } internalProvider.Remove(path); #endif }
protected internal override void Render(HtmlTextWriter output) { if (cachedData != null) { output.Write(cachedData); return; } if (control == null) { base.Render(output); return; } HttpContext context = HttpContext.Current; StringWriter writer = new StringWriter(); TextWriter prev = context.Response.SetTextWriter(writer); HtmlTextWriter txt_writer = new HtmlTextWriter(writer); string text; try { control.RenderControl(txt_writer); } finally { text = writer.ToString(); context.Response.SetTextWriter(prev); output.Write(text); } OutputCacheProvider provider = GetProvider(); DateTime utcExpire = DateTime.UtcNow.AddSeconds(duration); provider.Set(cacheKey, text, utcExpire);; context.InternalCache.Insert(cacheKey, text, dependency, utcExpire.ToLocalTime(), Cache.NoSlidingExpiration, CacheItemPriority.Normal, null); }
private static string GetFromCache(HttpContext context, string path) { OutputCacheProvider defaultOutputCacheProvider = OutputCache.Providers[OutputCache.DefaultProviderName]; return(defaultOutputCacheProvider != null ? defaultOutputCacheProvider.Get(path) as string : context.Cache.Get(path) as string); }
void RetrieveCachedContents() { cacheKey = CreateKey(); #if NET_4_0 OutputCacheProvider provider = GetProvider(); cachedData = provider.Get(cacheKey) as string; #else Cache cache = HttpRuntime.InternalCache; cachedData = cache [cacheKey] as string; #endif }
private static void AddToCache(HttpContext context, string path, string output) { OutputCacheProvider defaultOutputCacheProvider = OutputCache.Providers[OutputCache.DefaultProviderName]; if (defaultOutputCacheProvider != null) { defaultOutputCacheProvider.Add(path, output, DateTime.Now.AddSeconds(DefaultExpiry)); } else { context.Cache.Add(path, output, null, DateTime.Now.AddSeconds(DefaultExpiry), Cache.NoSlidingExpiration, CacheItemPriority.Low, null); } }
private string GetFromCache(HttpContext context, string path) { OutputCacheProvider oc = OutputCache.Providers[OutputCache.DefaultProviderName]; if (oc != null) { return(oc.Get(path) as string); } else { return(context.Cache.Get(path) as string); } }
private void AddToCache(HttpContext context, string path, string output) { OutputCacheProvider oc = OutputCache.Providers[OutputCache.DefaultProviderName]; if (oc != null) { oc.Add(path, output, DateTime.Now.AddSeconds(60)); } else { context.Cache.Add(path, output, null, DateTime.Now.AddSeconds(60), Cache.NoSlidingExpiration, CacheItemPriority.Low, null); } }
internal OutputCacheProvider GetDefaultProvider(OutputCacheProviderCollection providers) { string defaultProviderName = this.DefaultProviderName; if (defaultProviderName == "AspNetInternalProvider") { return(null); } OutputCacheProvider provider = (providers == null) ? null : providers[defaultProviderName]; if (provider == null) { throw new ConfigurationErrorsException(System.Web.SR.GetString("Def_provider_not_found"), base.ElementInformation.Properties["defaultProvider"].Source, base.ElementInformation.Properties["defaultProvider"].LineNumber); } return(provider); }
#pragma warning restore CC0022 // Should dispose object private static void ConfigureWebApi(IAppBuilder app, HttpConfiguration config) { // REQUIRED TO ENABLE HELP PAGES :) config.MapHttpAttributeRoutes(); config.EnableSwagger(c => { c.SingleApiVersion("v1", "KVLite.WebApiCaching"); c.IncludeXmlComments(HostingEnvironment.MapPath(@"~/App_Data/HelpPages/WebServiceHelp.xml")); }).EnableSwaggerUi(c => { c.DocExpansion(DocExpansion.None); }); // Enables KVLite based output caching. OutputCacheProvider.Register(config, CreateKernel().Get <ICache>()); // Add WebApi to the pipeline. app.UseWebApi(config); }
static OutputCache() { var providerType = new CacheSettingsManager().RetrieveOutputCacheProviderType(); if (providerType == null) { instance = new MemoryCacheProvider(); } else { try { instance = (OutputCacheProvider)Activator.CreateInstance(Type.GetType(providerType)); } catch (Exception ex) { throw new ConfigurationErrorsException(string.Format("Unable to instantiate OutputCacheProvider of type '{0}'. Make sure you are specifying the full type name.", providerType), ex); } } }
internal OutputCacheProvider GetDefaultProvider(OutputCacheProviderCollection providers) { // if defaultProvider is undefined, we'll default to the v2.0 OutputCache string defaultProviderName = DefaultProviderName; if (defaultProviderName == OutputCache.ASPNET_INTERNAL_PROVIDER_NAME) { return(null); } // if the defaultProvider is defined, it must be in the providers collection OutputCacheProvider defaultProvider = (providers == null) ? null : providers[defaultProviderName]; if (defaultProvider == null) { throw new ConfigurationErrorsException(SR.GetString(SR.Def_provider_not_found), ElementInformation.Properties["defaultProvider"].Source, ElementInformation.Properties["defaultProvider"].LineNumber); } return(defaultProvider); }
public OutputCacheManager(OutputCacheProvider outputCacheProvider, IKeyBuilder keyBuilder) { _outputCacheProvider = outputCacheProvider; _keyBuilder = keyBuilder; }
public void SetUp() { _outputCache = new OutputCacheProvider(new PersistentCache(new PersistentCacheSettings(), new MockClock())); }
public void TearDown() { _outputCache = null; }
public void SetUp() { _outputCache = new OutputCacheProvider(new PersistentCache(new PersistentCacheSettings(), clock: Kernel.Get <IClock>())); }
public OutputCacheManager() { _outputCacheProvider = OutputCache.Instance; _keyBuilder = new KeyBuilder(); }