Speed up unit tests for projects that use extensions.

Projects supporting extensions that used the test HTTP client would end
up reloading all extensions, creating RegisteredExtension entries, every
time a request was performed. This added up quite a bit over time.

This change does two things to address this problem.

1. The RegisteredExtension creation code has been improved. Instead of
   using get_or_create, we attempt a create and fall back on a get. This
   chops the number of queries in half, since we no longer are assuming
   there's an entry in the database already (which is a bad assumption,
   since earlier in the function, we checked and didn't see any).

   While here, I also fixed a bug where the wrong value was being
   used for the stored extension name, due to a scoping issue.

2. ExtensionsMiddleware no longer performs expiration checks if
   settings.RUNNING_TEST is True. It's up to the projects to set this
   for the test run, though.

Reviewed at https://reviews.reviewboard.org/r/5905/
Cache object lookups in WebAPIResource.get_object.

It's pretty common for different parts of a WebAPIResource subclass to
perform a get_object() call either on itself or on another resource.
This will happen in get_queryset() and in the permission-checking
functions. These checks are time-consuming and result in excess
database queries.

The built-in get_object() now supports caching of these objects. The
caches are tied to the request, so any redundant get_object() calls
taking place within that request will just use the original call's
result.

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