Overview
GAC’s caching system significantly improves performance by storing processed permissions and restrictions. This guide covers cache configuration, purging strategies, and optimization techniques.How Caching Works
Cache Flow
What Gets Cached
GAC caches three types of data per entity:- Permissions - Processed module access data
- Restrictions - Entity-specific restrictions
- Global Restrictions - System-wide restrictions
Cache Keys
Fromsrc/GAC.php:49:
- Permissions:
{prefix}_p_{entity_type}_{entity_id} - Restrictions:
{prefix}_r_{entity_type}_{entity_id} - Global restrictions:
{prefix}_r_global
Cache Configuration
Basic Setup
Custom Configuration
Environment-based TTL
- Development
- Staging
- Production
Dynamic TTL per Entity
Bypassing Cache
Force Database Query
Disable Cache Entirely
Clearing Cache
Clear Specific Entity Cache
src/GAC.php:202:
Purging Strategies
GAC provides targeted cache purging methods.Purge by User IDs
Purge by User IDs
Clear cache for specific users:Use case: When you update user permissions directly.
Purge by Client IDs
Purge by Client IDs
Clear cache for API clients:Use case: When you revoke or modify API client access.
Purge by Role IDs
Purge by Role IDs
Clear cache for all users/clients with specific roles:How it works: Queries Use case: When you modify role permissions.
gac_role_entity to find all users and clients with the specified roles, then purges their cache.From src/GAC.php:279:Global Purge
Global Purge
Clear all cached permissions or restrictions:Uses pattern matching from Use case: Major permission restructuring or system maintenance.
src/GAC.php:264:Cache Management Patterns
When Permissions Change
Batch Operations
Scheduled Cache Refresh
Performance Optimization
Cache Hit Rate Monitoring
Optimal TTL Selection
Memory Usage Optimization
Cache Storage Options
File-based Cache (Default)
- Simple setup
- No external dependencies
- Persistent across server restarts
- Slower than in-memory caches
- File I/O overhead
- Not ideal for high-concurrency
Redis Cache (Custom Adapter)
- Very fast (in-memory)
- High concurrency support
- Advanced features (TTL, patterns)
- External dependency
- Data lost on restart (unless persistent)
- Requires more setup
Memcached (Custom Adapter)
Similar to Redis - see Custom Adapters guide.Debugging Cache Issues
Verify Cache is Working
Check Cache Directory
Cache File Structure
Fromsrc/Adapters/CacheAdapter.php:66:
t: Expiration timestamp (Unix time)v: Actual cached data
Next Steps
Custom Adapters
Create custom cache and database adapters
Setup Adapters
Review adapter configuration options