1

I have an online store and the software is highly customized but not completely ours. We sell tours and some of them have reservations so I added a calendar to let them pick the date/time they want. Originally each cal_SelectionChanged() call was looking stuff up from the store database and that was, of course, horribly slow. I wanted to use a Data Dictionary to get the information once and use it whenever needed.

I have this class:

    public partial class ConLib_Custom_BuyTourProductDialog : System.Web.UI.UserControl

and this declared inside that class.

    static Dictionary<string, string> CustomFieldDict = new Dictionary<string, string>();

I also have a function to load all the bits from a database that I'll need on my page. My plan was to call this on Page_Load() and just access the info when needed.

    protected void LoadCustomFieldDictionary()
    {
        string _sku = _Product.Sku.Trim().ToLower();

        if (CustomFieldDict.ContainsKey("Sku"))
        {
            // is the dictionary entry for *this* sku?
            if (CustomFieldDict["Sku"] == _sku)
            {
                return; // already have this one.
            }
        }

        CustomFieldDict["Sku"] = _sku;
        CustomFieldDict["EventId"] = TTAUtils.GetCustomFieldValue(_Product, "EventId");
        CustomFieldDict["ResEventTypeId"] = TTAUtils.GetCustomFieldValue(_Product, "ResEventTypeId");

        etc.
    }

Then my boss loaded a page - ok, everything was fine - and changed one of the bits of data in the database to point to a different, wrong, ResEventTypeId. Reload the page and it has the new data. He changed it back to the original and it was "stuck" on the wrong information. I loaded a browser on my iPad and went there and it fed me the wrong info as well.

It seems that the server is caching that DataDictionary and even if we change the database all visitors, even in other sessions, get this cached wrong info.

  1. Do you think this assessment is right?
  2. What's the proper way to do this so that a visitor changing dates gets some kind of cached lookup speed and yet another browser gets a fresh set from the database?
  3. How do I make it "forget" what it thinks it knows and accept the new info until I fix it? Reset IIS?

Thankfully this is on a dev server and not my live store!

Thanks for your help. I've learned a lot about C# and .NET but it's shade-tree-mechanic type stuff and I lack the formal training that is out there and would really help in situations like these. Any help is appreciated!

Deverill
  • 971
  • 2
  • 17
  • 32

1 Answers1

0

For anyone coming by at a later time:

What Jonesy said is very true - statics are scary. I found out from one site (link to a link from his link) that statics like this are sticky to the Application Pool level so any other browser would get the "wrong" information.

For my situation I decided to use ViewState to store the info since it was small and my current V.S. isn't very large already. Beware doing this for large amounts of data but in my case it was the best.

Deverill
  • 971
  • 2
  • 17
  • 32