R
Richard Hollis
I have a site which is using caching for some frequently used pages. When
the page-level cache expires, or is expired by me, the page will get
re-rendered to a static HTML file and then shown to the user, after it has
been rendered.
Assume the cache is stale. Somebody comes along and requests the page. It
will then get re-generated, but whilst this is happening, if somebody comes
along and requests the page again then they can get an error because the
static HTML page file is still being recreated by the previous page request.
What I think I need is a mutex for the page to stop this from happening,
for the second page request, during cache refresh. So: 1st request owns the
mutex until finished, and, whilst it's updating, all other page requests
wait on the mutex.
How can I implement a 'mutex' style operation for this scenario in ASP or
handle it better to avoid this situation from happening? I've got my code
able to understand if the page being requested is actually being updated, so
I could just redirect the client back to the same script again, but at the
same time the update process itself takes less than a second, so if the page
could somehow wait for the operation to complete it would be a cleaner
operation. I tried wrapping the Sleep API in a COM object, but this didn't
seem to work and I'm just looking for a bit of a sanity check on the best
way to go about this.
Thanks
Richard
the page-level cache expires, or is expired by me, the page will get
re-rendered to a static HTML file and then shown to the user, after it has
been rendered.
Assume the cache is stale. Somebody comes along and requests the page. It
will then get re-generated, but whilst this is happening, if somebody comes
along and requests the page again then they can get an error because the
static HTML page file is still being recreated by the previous page request.
What I think I need is a mutex for the page to stop this from happening,
for the second page request, during cache refresh. So: 1st request owns the
mutex until finished, and, whilst it's updating, all other page requests
wait on the mutex.
How can I implement a 'mutex' style operation for this scenario in ASP or
handle it better to avoid this situation from happening? I've got my code
able to understand if the page being requested is actually being updated, so
I could just redirect the client back to the same script again, but at the
same time the update process itself takes less than a second, so if the page
could somehow wait for the operation to complete it would be a cleaner
operation. I tried wrapping the Sleep API in a COM object, but this didn't
seem to work and I'm just looking for a bit of a sanity check on the best
way to go about this.
Thanks
Richard