Skip to content

[ENG-740] 3/6 - Use DSR Cache store for clearing cached DSR data #7482

Open
johnewart wants to merge 6 commits intojohnewart/ENG-740/1-dsr-cache-storagefrom
johnewart/ENG-740/2-key-clearing-logic
Open

[ENG-740] 3/6 - Use DSR Cache store for clearing cached DSR data #7482
johnewart wants to merge 6 commits intojohnewart/ENG-740/1-dsr-cache-storagefrom
johnewart/ENG-740/2-key-clearing-logic

Conversation

@johnewart
Copy link
Collaborator

@johnewart johnewart commented Feb 24, 2026

Ticket ENG-2759

Description Of Changes

Uses the DSR cache store to delete cache keys; since the new write path isn't being used this (by design) falls back to doing the same as the existing logic only it uses SCAN instead of KEYS which is non-blocking. When the writes use the new path then we will update it to use the index instead; this way we can keep current behavior while rolling over to new.

Code Changes

  • Changes the privacy request to use the DSRStore's clear method and adds tests for it

Steps to Confirm

No manual steps needed

Pre-Merge Checklist

  • Issue requirements met
  • All CI pipelines succeeded
  • CHANGELOG.md updated
    • Add a db-migration This indicates that a change includes a database migration label to the entry if your change includes a DB migration
    • Add a high-risk This issue suggests changes that have a high-probability of breaking existing code label to the entry if your change includes a high-risk change (i.e. potential for performance impact or unexpected regression) that should be flagged
    • Updates unreleased work already in Changelog, no new entry necessary
  • UX feedback:
    • All UX related changes have been reviewed by a designer
    • No UX review needed
  • Followup issues:
    • Followup issues created
    • No followup issues
  • Database migrations:
    • Ensure that your downrev is up to date with the latest revision on main
    • Ensure that your downgrade() migration is correct and works
      • If a downgrade migration is not possible for this change, please call this out in the PR description!
    • No migrations
  • Documentation:
    • Documentation complete, PR opened in fidesdocs
    • Documentation issue created in fidesdocs
    • If there are any new client scopes created as part of the pull request, remember to update public-facing documentation that references our scope registry
    • No documentation updates required

This uses the `clear` method on the DSR cache store, which underneath
the hood uses `scan` (if needed, will try to use the set-based key
index if that particular ID is being tracked).

Adds some tests and removes the dependency on
get_all_cache_keys_for_privacy_request
@johnewart johnewart requested a review from JadeCara February 24, 2026 22:48
@johnewart johnewart requested a review from a team as a code owner February 24, 2026 22:48
@vercel
Copy link
Contributor

vercel bot commented Feb 24, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

2 Skipped Deployments
Project Deployment Actions Updated (UTC)
fides-plus-nightly Ignored Ignored Preview Feb 25, 2026 1:31am
fides-privacy-center Ignored Ignored Feb 25, 2026 1:31am

Request Review

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 files reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

from fides.api.util.identity_verification import IdentityVerificationMixin
from fides.api.util.logger import Pii
from fides.api.util.logger_context_utils import Contextualizable, LoggerContextKeys
from fides.common.cache import get_dsr_cache_store
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get_dsr_cache_store is not defined or exported in fides.common.cache. This import will fail with ImportError.

The function needs to be added to src/fides/common/cache/__init__.py. Based on the usage pattern and test mocking, it should be a context manager like:

Suggested change
from fides.common.cache import get_dsr_cache_store
from fides.api.util.cache import get_cache
from fides.common.cache import get_dsr_cache_store, DSRCacheStore

Add to /src/fides/common/cache/__init__.py:

@contextmanager
def get_dsr_cache_store() -> Iterator[DSRCacheStore]:
    """Get a DSR cache store instance using the application Redis cache."""
    from fides.api.util.cache import get_cache
    redis_client = get_cache()
    manager = RedisCacheManager(redis_client)
    yield DSRCacheStore(manager)

)

def keys(self, pattern):
import fnmatch
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

importing fnmatch inside method violates custom rule - move to top of module

Suggested change
import fnmatch
return [k for k in self._data if fnmatch.fnmatch(k, pattern)]

Add at top of file:

import fnmatch

Context Used: Rule from dashboard - Move imports to the top of the module rather than inside functions. Avoid placing imports inside tes... (source)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@ethyca ethyca deleted a comment from greptile-apps bot Feb 24, 2026
@johnewart
Copy link
Collaborator Author

@greptileai review

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 24, 2026

Greptile Summary

This PR refactors the privacy request cache clearing logic to use the new DSRCacheStore, which leverages Redis SCAN instead of the blocking KEYS operation. The implementation is part of a phased migration strategy that maintains backward compatibility with legacy cache keys while enabling a transition to the new indexed key format.

Key Changes:

  • Replaced direct Redis operations in clear_cached_values() with DSRCacheStore.clear() method
  • Added get_dsr_cache_store() context manager and get_redis_cache_manager() helper in cache.py
  • Consolidated test infrastructure by creating shared MockRedis and MockPipeline in mock_redis.py
  • Added comprehensive integration tests covering legacy, new, and mixed cache key scenarios
  • The fnmatch import is correctly placed at the top of mock_redis.py module

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The refactoring is well-designed with comprehensive test coverage, proper error handling, and backward compatibility. The use of SCAN over KEYS is a non-blocking improvement. All changes are well-tested with integration tests covering edge cases. The implementation follows established patterns and the previous thread's import issue has been properly resolved.
  • No files require special attention

Important Files Changed

Filename Overview
src/fides/api/models/privacy_request/privacy_request.py Refactored to use DSRCacheStore for clearing cached values - clean implementation using context manager pattern
src/fides/api/util/cache.py Added get_dsr_cache_store() context manager and get_redis_cache_manager() helper - clean implementation with proper imports
tests/common/cache/mock_redis.py New shared MockRedis test utility - consolidates test infrastructure, includes fnmatch import at top level
tests/common/cache/test_dsr_store_clear_integration.py New integration tests for privacy_request.clear_cached_values() - comprehensive coverage of legacy, new, and mixed key scenarios

Last reviewed commit: 86557db

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

8 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

Copy link
Contributor

@JadeCara JadeCara left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks solid! No notes!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants