How to block subsequent RESTful requests to same page until results are built and cached? RRS feed

  • Question

  • I have a RESTful webservice.  Each request is dispatched to a handler, evaluated if the requested URL has already been cached, and sent back the content (either from cache or newly constructed).

    There are some URLs that are heavily used and so suppose that a request takes one second to generate before being cached.  If in that time the same request is made many times, each will go through the construction phase because it is not in the cache.  I would like to improve this design.  I would like to be able to block/suspend other requests until the first has been completed and cached, then the other will simply pull it from the cache.  This would be on a request-by-request basis.  If request A comes in many times (and has not been cached), then all but the first will block while if request B comes in during that time it will continue as normal.

    I was looking at using ConcurrentDictionary and ManualResetEvent.  Are there any articles documenting this design pattern so that I can consult to make sure I don't add additional performance problems?

    • Moved by Paul Zhou Monday, January 17, 2011 10:47 AM ASP.NET (From:Visual C# General)
    Friday, January 7, 2011 6:36 PM