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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T08:09:33+00:00 2026-05-20T08:09:33+00:00

This might just be a theoretical question but I haven’t been able to find

  • 0

This might just be a theoretical question but I haven’t been able to find a satisfying answer to it.

I’m using the cache on one of my sites which got me thinking about it’s data and when and if it changes. Can the cache change during the execution of some code?

Here’s an example

if (Cache["name"] != null) {

    // Long and heavy code execution done here

    if (Cache["name"] == null) Response.Write("Lost the data");
}

Can the process that change the cache run parallel with the above code or does it wait until it has finished?
Is there a theoretical chance that this would print “Lost the data”?

If yes, is it always good practice to save the variable first or always check for null and never not null?

Thanks in advance!

/Niklas

  • 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-20T08:09:33+00:00Added an answer on May 20, 2026 at 8:09 am

    Absolutely it can.

    Always snapshot values from cache, and work with the snapshot:

    var snapshot = Cache["name"];
    if(snapshot != null) {...}
    

    and use snapshot throughout. When it comes to threading, the above is generally a sane approach; the only caveat being you might want to look at Interlocked for a range of methods that let you see (safely) whether a variable/field changed while you weren’t looking, and only apply a change it it hadn’t changed.

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

Sidebar

Related Questions

Ok, this might just be a dumb question, but I was wondering if Bluetooth
This might sound like a stupid question but just trying to learn something here.
This might be a simple question but I'm just picking this up so please
This might just be an impossible question, but I want to give it a
This might just come as a very silly question, but i am really frustrated
This question might be theoretical but i think some of the cases it makes
This might turn out to be a stupid typo but just incase there is
This might be a naive question. However, I am just trying to understand why
This might not have a major usecase in projects, but I was just trying
I feel like this might be really simple but I'm just not getting it

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.