Attempt to fix DynamicURLResolver with threads.

We had some occasional bugs where Django would fail to look up items
from URL resolvers, generating a HTTP 500. This is likely due to a
lookup occurring while the cache is being cleared.

This change attempts to improve the way we handle clearing of caches.
Instead of wiping the entries and expecting Django's URLResolvers to
rebuild them when appropriate, we now directly call their _repopulate()
method. This method will generate new copies of the dictionaries and
then immediately set them, without leaving any time where the
dictionaries would be empty.

This should ensure that a valid lookup will always succeed, without any
risk of the types of failures we've seen.

It also surrounds this in a lock, hopefully preventing any clashes
during the repopulation process.

Reviewed at https://reviews.reviewboard.org/r/6606/