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 646847
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T21:39:27+00:00 2026-05-13T21:39:27+00:00

In order to synchronise access to a Dictionary object in the ASP.NET cache, it

  • 0

In order to synchronise access to a Dictionary object in the ASP.NET cache, it is recommended that a synchroniser object be used.

Dino Esposito recommends a static variable as the target for locking (See http://www.drdobbs.com/cpp/184406369). However, this will only work if the ASP.NET Cache values have the same scope (or narrower scope) than static variables.

Does anyone know of documentation to this effect?

  • 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-13T21:39:27+00:00Added an answer on May 13, 2026 at 9:39 pm

    // Update based on comment
    The cache is unique per app domain, so you don’t need to worry. See MSDN here

    There is one instance of the Cache
    class per application domain. As a
    result, the Cache object that is
    returned by the Cache property is the
    Cache object for all requests in the
    application domain.

    // Original answer

    I’m not sure I quite understand your question. Anything in the cache is globally accessible (or at least accessible by anything that has access to the cache object).

    This code would be safe as long as it is the only place you access the object.

        private static readonly object lockme = new object();
        public void SetDictionaryValue(string key, string value)
        {
            lock (lockme)
            {
                var lookup = (Dictionary<string, string>)GetFromCache("LookupDictionary");
                lookup["key"] = value;
            }
        }
    
        public string GetDictionaryValue(string key)
        {
            lock (lockme)
            {
                var lookup = (Dictionary<string, string>)GetFromCache("LookupDictionary");
                return lookup["key"];
            }
        }
    

    But yes, it’s not guaranteed to be safe as there could be other code that retrieves the dictionary from the cache somewhere else and modifies it. Not sure how you could guarantee that that couldn’t happen. I mean you could use a GUID as a key, but you can iterate over all the cache variables anyway.

    I’m not sure if I’m helping you here?

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

Sidebar

Related Questions

Order props: Object selectedItems: Array[1] 0: SelectedItem length: 1 __proto__: Array[0] __proto__: Order I
I'm using NSUserDefaults to keep an object in sync across several UIViewController s that
Threads A, B, C in that order, reach synchronized method f() in a single
I would like to use the iTunes user mail account in order to synchronise
Lucene documentation states that single instances of IndexSearcher and IndexWriter should be used for
I have an application that connects to a database and can be used in
I want to access my applicant database that's why I created a DAO class
In order to synchronize/queue access to a shared resource, I am about to use
There is a singleton class that n threads can access. Each thread loads the
I have some code that I want to only allow access to by one

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.