Note that there are some explanatory texts on larger screens.

plurals
  1. POIs it advisable to use HashSet as a static global on a webserver?
    primarykey
    data
    text
    <p>I want to create a "temporary cache lookup" to speed up a file lookup on my webserver.</p> <p>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.</p> <p>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.</p> <p>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.</p> <p>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.</p> <p><strong>Edit with regards to race conditions:</strong> <br>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.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload