Re: Test race condition? (unit test?) [message #175590 is a reply to message #175589] |
Mon, 10 October 2011 14:43 |
The Natural Philosoph
Messages: 993 Registered: September 2010
Karma:
|
Senior Member |
|
|
Simon wrote:
>>
>> The real question here is - what is the problem you're trying to
>> resolve. Without knowing that, it's difficult to recommend if there is a
>> better way.
>>
>
> Thanks for the reply. I am not trying to solve a problem per say.
> I am 'just' trying to prevent duplicate work.
>
> When a request for a certain page first comes, it make a few calls to
> the db and then caches the page.
> Once the page is cached, only one call needs to be made.
>
> But I sometime get hundreds of calls for a certain page, all at the same
> time.
> So it would make no sense for all of them to create the very same cache
> page.
>
> It makes more sense for the first request to cache the page wile others
> wait a few milliseconds for it.
> By locking the page, the first requests is instructing others that the
> work is already been done and they should wait a few milliseconds.
>
> Every so often, (for various reasons), the cache is marked as 'dirty'
> and a new cache will then be recreated.
> If one request 'locks' the page, and a cache is available, then the
> other requests will continue to serve the dirty page.
>
> I just want to prevent the same cache been created by many requests at
> the same time.
>
well if you are using a database, it will already have cached the data
comprising the page.
Unless your manipulation of that page is excessively memory or CPU
intensive, there is little point in caching the result too.
And that is probably something a proxy server does better, anyway.
> I hope this makes sense.
>
> Simon
|
|
|