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

  • Home
  • SEARCH
  • 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 6154993
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:21:31+00:00 2026-05-23T20:21:31+00:00

The MSDN documentation for MemoryCache.Set unfortunately doesn’t state explicitly whether it is thread-safe or

  • 0

The MSDN documentation for MemoryCache.Set unfortunately doesn’t state explicitly whether it is thread-safe or not.

Is it safe to use .Get() and .Set() from several threads without an explicit lock?

  • 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-23T20:21:31+00:00Added an answer on May 23, 2026 at 8:21 pm

    Yes, the MemoryCache class is thread safe:

    System.Runtime.Caching.MemoryCache is threadsafe. Multiple concurrent
    threads can read and write a MemoryCache instance. Internally
    thread-safety is automatically handled to ensure the cache is updated
    in a consistent manner.

    What this might be referring to is that data stored within the cache
    may itself not be threadsafe. For example if a List is placed in
    the cache, and two separate threads both get a reference to the cached
    List, the two threads will end up stepping on each other if they
    both attempt to update the list simultaneously.

    This being said the Get and Set methods are thread safe but if the data structure you might be storing into this cache is not thread safe you might get into trouble. Imagine for example that you stored a dictionary inside this cache. Then while thread1 uses Get to fetch the dictionary and starts reading from it, thread2 uses Get to fetch this same dictionary and tries to write to it. While the Get operation will be thread safe what will happen next could be pretty nasty.

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

Sidebar

Related Questions

The msdn documentation states that a static generic Queue is thread-safe. Does this mean
In MSDN documentation we see : Console Thread Safety This type is thread safe.
From the MSDN documentation: Synchronized supports multiple writing threads, provided that no threads are
It is unclear to me from the MSDN documentation if I should provide a
Is there an easy way to produce MSDN-style documentation from the Visual Studio XML
The MSDN documentation indicates that this API is not limited to Windows Mobile, but
The MSDN documentation for the is keyword says: expression is not null Why? If
The MSDN documentation doesn't generally specify the assembly a namespace is in, so there's
According to the MSDN documentation , transactional NTFS doesn't seem to allow one to
Paraphrasing from this MSDN documentation ... An INSERT statement is generated by the Entity

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.