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::SafeRequestStorecaching - Cache key for
GroupsFinderincludesuser_idandmin_access_level - Cache key for
ProjectsFinderincludes onlyuser_id - Caching is controlled by
search_finders_redis_cachefeature 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
- Groups:
-
Storage: Redis via
Rails.cache(usesGitlab::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