✨ Add built-in tenant-aware APQ caching support#70
Merged
Conversation
TDD Cycle Complete: - RED: Tests written expecting context parameter (initially failed) - GREEN: Added context parameter with default None (tests pass) - REFACTOR: Code cleaned up per linting rules Changes: - APQStorageBackend methods now accept optional context parameter - Added extract_tenant_id() helper for context parsing - Backward compatibility maintained (context defaults to None) - All existing tests pass (5 passed, 1 expected fail for Phase 3) Next: Phase 2 - Router context propagation
TDD Cycle Complete: - RED: Tests expecting context propagation failed - GREEN: Updated router and middleware to pass context - REFACTOR: Code formatted and cleaned per linting rules - QA: All integration tests pass Changes: - Router now passes context to APQ backend methods - handle_apq_request_with_cache accepts and forwards context - store_response_in_cache accepts and forwards context - Backward compatibility maintained Test results: - New context propagation tests: 3 passing - APQ middleware integration: 9 passing - No regressions detected Next: Phase 3 - Tenant-specific response caching
Complete implementation of tenant-aware APQ caching: Phase 3: Tenant-Specific Caching - TenantAwareMemoryBackend implementation - Cache key generation with tenant isolation - Comprehensive tests for tenant isolation - Cache invalidation per tenant Phase 4: Documentation & Examples - Complete guide for APQ tenant context support - Working multi-tenant example with statistics - Security considerations and best practices - Migration guide for existing applications Features demonstrated: - Tenant-specific response caching - Prevention of cross-tenant data leakage - Per-tenant cache invalidation - Cache hit rate tracking per tenant - Backward compatibility with non-tenant systems The feature is complete and ready for production use!
- MemoryAPQBackend now uses tenant-aware cache keys - PostgreSQLAPQBackend adds tenant_id column and composite keys - No backward compatibility constraints - fresh implementation - All tests updated and passing 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
- Removed redundant TenantAwareMemoryBackend from examples - Cleaned up all phase comments from tests - Updated documentation to reflect built-in tenant support - Removed transitional comments from implementations - Repository now reflects clean, intended design The codebase now sparks joy ✨ 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements built-in tenant-aware caching for Automatic Persisted Queries (APQ), enabling secure multi-tenant applications with automatic response isolation.
Key Changes
MemoryAPQBackendandPostgreSQLAPQBackendnow automatically isolate cached responses by tenant when context is providedImplementation Details
MemoryAPQBackend
{tenant_id}:{hash}PostgreSQLAPQBackend
tenant_idcolumn to responses table(hash, COALESCE(tenant_id, ''))Security
Testing
Usage
Documentation
docs/apq_tenant_context_guide.mdexamples/apq_multi_tenant.py🤖 Generated with Claude Code