Cache path lookups for namespaces [RUN ALL RSPEC] [RUN AS-IF-FOSS]

Merged Robert May requested to merge route-caching into master

What does this MR do?

Ensures that path lookups for projects/namespaces/groups are cached, both for a request and until the records are updated.

This introduces a bunch of early returns to make as much use of preloaded data as possible before defaulting to a cache wrapping the original code.

This will heavily reduce the impact of one of our top 10 queries by volume.

Also includes the first caching utility method in Gitlab::Cache that I'm going to expand upon later.

Resolves #325334

Screenshots (strongly suggested)

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:

  • Label as security and @ mention @gitlab-com/gl-security/appsec
  • The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • Security reports checked/validated by a reviewer from the AppSec team
Edited by Robert May