Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3280330
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T19:41:31+00:00 2026-05-17T19:41:31+00:00

Recently, I’ve been experimenting with caching objects with HttpRuntime.Cache and I was generally under

  • 0

Recently, I’ve been experimenting with caching objects with HttpRuntime.Cache and I was generally under the impression that if I “added” something to the cache like this:

HttpRuntime.Cache.Insert("Test", "This is a test!", null, 
     Cache.NoAbsoluteExpiration, Cache.NoSlidingExpiration, 
     CacheItemPriority.NotRemovable, new CacheItemRemovedCallback(FileChanged));

that the “NotRemovable” and “NoExpiration” flags would keep the object in-memory for the duration of the application. But was finding that at the end of certain page requests, the HttpRuntime.Cache would be completely empty!

Tracing thru and setting a breakpoint inside my Callback “FileChanged” I could see that indeed something was “removing” my object (and every other object in the cache), but I couldn’t figure out why. So eventually, I started disabling other things that I thought might affect this subsystem.

Eventually, I commented out the line:

WebConfigurationManager.OpenWebConfiguration("~").Save;

I had been mostly retrieving data from “web.config” in the AppSettings region, but occasionally writing back to AppSettings and saving the changes using the above command. I knew from reading that the “web.config” is cached, but saving my changes back to it shouldn’t flush all of HttpRuntime.Cache, right?

Is this a bug? Or are the two caches somehow linked in a way that I should be made aware of?

EDIT:

Ok, I’ve made this super reproducible if anyone wants to try this on their own machine. (I’m running VS2008 Pro w/ MVC2 targeting .NET 3.5) Just start up a new MVC2 project and paste the following into the HomeController over whatever is already there:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Configuration;
using System.Configuration;

namespace BackButtonTest.Controllers
{
    [HandleError]
    public class HomeController : Controller
    {
        private string MESSAGE = "Message";
        public ActionResult Index()
        {
            ViewData[MESSAGE] = HttpRuntime.Cache.Get(MESSAGE);
            Configuration Config = WebConfigurationManager.OpenWebConfiguration("~");
            Config.AppSettings.Settings.Add("SomeKey", "SomeValue");
            Config.Save();
            return View();
        }

        public ActionResult About()
        {
            HttpRuntime.Cache[MESSAGE] = "This is pulled from the HttpRuntime.Cache";
            return View();
        }
    }
}

Then follow these steps:

  1. Start-up the app in debug mode.
  2. Click on the “About” link. This loads a string into the Cache.
  3. Click on the “Home” link. String is pulled from the Cache and stuck in ViewMessage dictionary. Some key/value pair is written to web.config and saved. String from cache should appear on the Home page.
  4. Click on the “Home” link again. String should be pulled from the cache, but it’s not.
  5. Stop program. Comment out the 3 lines that start with “Config”. Restart the program.
  6. Try steps 1 thru 4 again. Notice how the HttpRuntime.Cache has not been emptied.

Weird, huh?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T19:41:32+00:00Added an answer on May 17, 2026 at 7:41 pm

    Writing to your web.config will force the application to restart, and, most likely, events for emptying the cache, in-proc sessionstate etc. will go off. Try and write down some log in global.asax Application_End (or whatever the name of the method is 🙂 )

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Recently I have been investigating the possibilities of caching in ASP.NET. I rolled my
Recently, I've been dealing with an error with accessing MAPI via the .NET framework
Recently our site has been deluged with the resurgence of the Asprox botnet SQL
Recently Jeff has posted regarding his trouble with database deadlocks related to reading. Multiversion
Recently, I started changing some of our applications to support MS SQL Server as
Recently I had to develop a SharePoint workflow, and I found the experience quite
Recently we got a new server at the office purely for testing purposes. It
Recently, I read an article entitled SATA vs. SCSI reliability . It mostly discusses
Recently I ran into this error in my web application: java.lang.OutOfMemoryError: PermGen space It's
Recently a friend and I were talking about securing stored procedure code in a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.