locked
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?

    • Edited by Peter Rilling Tuesday, January 4, 2011 1:52 AM Updated grammar
    Monday, January 3, 2011 7:05 AM

All replies

  • Have you considered REST singleton WCF webservice?
    Wednesday, January 12, 2011 2:15 PM