Question 1 (RegisterAsyncTask)
It is very important to remember: from the point of view of the client / user / browser, this does NOT make the request asynchronous. If the Task you are registering takes 30 seconds, the browser will still wait another 30 seconds. The only thing RegisterAsyncTask does is to free your workflow back to IIS for the duration of the asynchronous call. Do not get me wrong - this is still a valuable and important technique. However, for the user / browser that makes this particular request, it does not have a noticeable effect on response time.
Question 2
This may not be the best solution to your problem, but this is what I used in the past that could help: when you add your item to the cache , specify absoluteExpiration and onRemoveCallback. Create a function that receives the latest data and puts it in the cache: this is a function that you must pass as onRemoveCallback. Thus, each time your cached data expires, a callback occurs to return the new data to the cache; because the callback results from a cache expiration event, there is no user request waiting 7-10 seconds needed to cache fresh data.
This is not a perfect design. Some reservations:
- How to load cache initially? The easiest way is to call the cache loader function from the Application_Start function.
- Every 15 minutes, a window with 7-10 seconds will appear in which the cache is empty. Any requests during this time will have to receive the data themselves. Depending on your patterns of using the system, this may be an acceptable small window, and during it there will only be very few requests.
- Cache fault tolerance is not guaranteed when your cache code expires. If the system is under extremely heavy load, there may be a delay before the callback is called and the cache is reloaded. Again, depending on the use of your system, this may be a problem or a problem.
Sorry, I donβt have a bulletproof answer for you (I will follow this thread - maybe another SO'er does!). But, as I said, I used this approach with some success, and if your system does not have an extremely high load, it should help resolve the issue.
Edit: slight deviation from the above approach based on OP comment
You can cache a dummy value and use it exclusively to run the refreshCachedData function. It is not particularly elegant, but I have done it before. :)
To develop: save your actual data in a cache with the "MyData" key, without expiration and without onRemoveCallback. Each time you cache fresh data in "MyData", you also add a dummy value to your cache: "MyDataRebuildTrigger", after 15 minutes and with onRemoveCallback, which restores your actual cached data. Thus, there is no 7-10 second space when "MyData" is empty.