Skip to content

Conversation

@mubbi
Copy link
Owner

@mubbi mubbi commented Aug 5, 2025

Introduces comprehensive caching for user roles and permissions to optimize authorization performance and reduce database queries.

Changes

Commit: 4d75d97 - perf: roles permissions cache

Files Modified

🆕 New Files

🔧 Modified Files

🧪 Test Files Added

Key Features

  • Cached Role/Permission Checks: hasCachedPermission(), hasCachedRole(), etc.
  • Bulk Permission Checks: hasAnyCachedPermission(), hasAllCachedPermissions()
  • Cache Management: Console command with --user-id and --all options
  • Version-based Invalidation: Efficient bulk cache clearing
  • 1-hour TTL: Configurable cache duration

Stats

  • +1,162 lines added
  • 12 files changed
  • 632+ lines of comprehensive tests
  • Zero breaking changes

Usage

# Clear all user caches
php artisan cache:clear-roles-permissions --all

Clear specific user cache

php artisan cache:clear-roles-permissions --user-id=1

Testing

php artisan test tests/Feature/Models/UserCachingTest.php
php artisan test tests/Feature/Console/ClearRolePermissionCacheTest.php
php artisan test tests/Feature/Services/UserServiceTest.php

@mubbi mubbi merged commit 75e14f8 into develop Aug 5, 2025
4 checks passed
@mubbi mubbi deleted the feature/optimize-roles-permissions branch August 5, 2025 22:30
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