We have some code which allows an image to be requested in different sizes and if it doesn't exist it creates it in that size and stores it. The problem we have is multiple requests when the image doesn't exist and it tries to create it for the first time.
While we are not currently on a web farm or distributed across multiple machines that is where we want to get to so what we need is a way to lock that section while only one thread/process creates the re-sized image and then allow any threads to continue returning the image.
What is the best way in ASP.NET C# to lock across multiple threads/machines (in a web farm scenario). I guess the only real choice is with some sort of DB table which we can store locks in perhaps on the image filename/id but then do the other threads have to keep calling the DB to see if the lock has been released?
If anyone has any experience of this type of scenario it would be appreciated. We are using ASP.NET MVC 4 with C# 4.5 and SQL Server 2008.