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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T12:21:38+00:00 2026-05-12T12:21:38+00:00

I want to create a temporary cache lookup to speed up a file lookup

  • 0

I want to create a “temporary cache lookup” to speed up a file lookup on my webserver.

What I have now is a folder full of images, and if a user requests an image I use a File.Exists(…) to check to see if the image exists. If it doesn’t, download it from another server, and either way, redirect the user to it.

The problem with this is that a lot of requests at once cause File.Exists() to hang. I would like to keep a quick and dirty HashSet of filenames known to be in the local folder, so that if the the user requests a file, and it exists in the HashSet, just redirect to it without doing the File.Exists(), if it doesn’t exist int he HashSet, do the File.Exists() then add it.

I know that the HashSet would get blown away if the server ever gets restarted, but I’m not worried about that, because it would quickly “rebuild” itself with the most requested images using the above scenario.

The main question is, since this object would be getting called from multiple users, and various requests would all be adding items to the set, would this cause a problem? Up to now all I’ve used in the static global sense on webservers is DB connection strings or an email address to send alerts to, etc.

Edit with regards to race conditions:

Yes I was thinking of race conditions. But is a race condition even possible on a single HashSet? Since it only allows unique values, wouldnt the second attempt to add a value fail? At which point I would just ignore the error and continue on.

  • 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-12T12:21:39+00:00Added an answer on May 12, 2026 at 12:21 pm

    It makes sense. However, make sure you take care of possible race conditions. You could use the ReaderWriterLockSlim class to control access to the object from different threads.

    UPDATE:

    You absolutely need to lock the object appropriately, as the Add method is not an atomic operation. You can even leave the object in an inconsistent state if you add two things simultaneously.

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

Sidebar

Related Questions

No related questions found

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.