Caching & Performance Tuning
Relevant source files
The following files were used as context for generating this wiki page:
Introduction
The RateGuru platform employs a structured caching strategy to optimize performance and handle high-frequency data access patterns, particularly for post listings and feed generation. By leveraging Laravel's native caching infrastructure and specialized manager classes, the system reduces database load and minimizes latency for end-users.
The architecture emphasizes "SQLite first" development and utilizes local storage for cache data in standard environments, ensuring that performance tuning is aligned with the project's core stack and deployment guidelines. Sources: AGENTS.md, README.md, tests/Feature/Docs/DeploymentDocsTest.php
Cache Architecture and Management
Post List Cache Management
The primary mechanism for feed performance is the PostListCacheManager. This service is responsible for generating stable cache keys based on user-provided filters and managing the lifecycle of cached post data. It ensures that identical feed requests (same sort order, search terms, and pagination) resolve to the same cache entry. Sources: app/Support/Cache/PostListCacheManager.php, tests/Unit/Support/Cache/PostListCacheManagerTest.php:21-34
The system generates cache keys using a standardized format: post-list:feed:page={page}:perPage={perPage}:search="{search}":sort="{sort}":tag="{tag}". Sources: tests/Unit/Support/Cache/PostListCacheManagerTest.php:21-34
The following diagram illustrates the flow of a feed request through the cache manager:
The diagram shows the decision logic used by the PostListCacheManager to determine whether to serve data from the cache or the database. Sources: app/Support/Cache/PostListCacheManager.php, tests/Unit/Support/Cache/PostListCacheManagerTest.php:14-19
Component Summary
| Component | Responsibility | Relevant Files |
|---|---|---|
PostListCacheManager | Generates stable keys and handles remember logic for post feeds. | app/Support/Cache/PostListCacheManager.php |
config/cache.php | Global cache configuration and driver selection. | config/cache.php |
storage/framework/cache/data | Physical location for local cache storage. | tests/Feature/Docs/DeploymentDocsTest.php |
Deployment and Environment Optimization
Performance tuning in RateGuru is heavily dependent on environment configuration. While the project uses SQLite by default, it explicitly forbids adding Redis without a separate task, maintaining a lean dependency profile for Phase 1. Sources: AGENTS.md, tests/Feature/Docs/DeploymentDocsTest.php
Production Performance Checklist
To ensure optimal performance in production, several environment variables and artisan commands are required:
- Environment:
APP_ENV=productionandAPP_DEBUG=falseare critical for disabling overhead-heavy debugging tools. - Path Optimization: Use
php artisan storage:linkto ensure efficient access to public assets. - Cache Persistence: The system expects the directory
storage/framework/cache/datato exist and have correct permissions to prevent I/O failures.
Sources: tests/Feature/Docs/DeploymentDocsTest.php:6-14, 40-52
Infrastructure Constraints
The diagram outlines the allowed and forbidden performance tools within the current project scope. Sources: AGENTS.md
Implementation Details
Stable Key Generation
The PostListCacheManager ensures that filters are applied consistently to the cache key. This prevents cache fragmentation where slightly different request formats might result in multiple cache misses for the same logical data.
// Example of generated key structure
// post-list:feed:page=1:perPage=12:search="pasta":sort="newest":tag="italian"
Sources: tests/Unit/Support/Cache/PostListCacheManagerTest.php:21-34
Queue and Background Processing
Performance is also tuned by offloading heavy tasks to background workers. The system supports a QUEUE_CONNECTION (defaulting to sync or database in standard setups) to handle non-blocking operations. Even without Redis, the php artisan queue:work command is used to maintain responsiveness. Sources: tests/Feature/Docs/DeploymentDocsTest.php:60-70
Conclusion
Caching and performance tuning in RateGuru focus on effective key management via the PostListCacheManager and strict adherence to environmental configuration. By optimizing for the local stack (SQLite and local cache drivers) and leveraging Laravel's built-in optimization commands, the application maintains high performance without introducing external infrastructure complexity like Redis during early development phases.