Replaced ad-hoc caching of get_models with lru_cache.

Invalidate properly the cache whenever all_models or app_configs change.
This fixes some isolation issues in the test suite.