Add Redis cache for Search::GroupsFinder and Search::ProjectsFinder

Summary

Closes #591202 (closed)

Implements short-lived Redis caching (5 minutes TTL) for Search::GroupsFinder and Search::ProjectsFinder to reduce repeated authorization queries across multiple search requests from the same user.

Changes

  • Adds Redis caching layer on top of existing Gitlab::SafeRequestStore caching
  • Cache key for GroupsFinder includes user_id and min_access_level
  • Cache key for ProjectsFinder includes only user_id
  • Caching is controlled by search_finders_redis_cache feature flag (default: disabled)
  • Adds comprehensive specs for both finders with and without caching

Cache Specifications

  • Duration: 5 minutes TTL
  • Cache key format:
    • Groups: search_user:{user_id}:min_access_level:{level}:groups
    • Projects: search_user:{user_id}:projects
  • Storage: Redis via Rails.cache (uses Gitlab::Redis::Cache)
  • Scope: Per-user basis
  • Invalidation: Time-based expiration (TTL)

Testing

All existing tests pass, plus new tests covering:

  • Feature flag disabled: no caching behavior
  • Feature flag enabled: caching and cache retrieval
  • Different cache keys for different min_access_level values

Merge request reports

Loading