Caching Architecture
The Vactory caching architecture uses Redis as an intermediate layer between your Next.js frontend and Drupal backend to dramatically improve performance and reduce server load.
Architecture Overview
Request Flow Process
The caching system follows a strategic flow to optimize performance:
1. User Requests a Page
When a user requests a page from the Next.js app, the request is initially handled by the Next.js server.
2. Next.js Checks Redis Cache
When the user requests a page, the Next.js app first checks if the requested page exists in the Redis cache. It does so by querying the Redis cache with a specific key that represents the requested page.
3. Cached Page Exists
If the requested page is found in the Redis cache, Next.js retrieves the page data from the cache and sends it back to the user as the response (after preparing the correct HTML). This eliminates the need to make a request to the Drupal backend app, resulting in faster response times.
4. Cached Page Doesn't Exist
If the requested page is not found in the Redis cache, Next.js proceeds to the next step.
5. Next.js Requests Page from Drupal
Next.js sends a request to the Drupal backend app, asking for the data needed to render the requested page.
6. Drupal Fetches Data
The Drupal backend app receives the request from Next.js and sends the JSON response back to Next.js app.
7. Next.js Stores Page Data in Redis Cache
Next.js caches the received JSON data in Redis for future use, so that subsequent requests for the same page can be served directly from the cache.
8. Next.js Sends Page to User
Finally, Next.js sends the rendered page as the response to the user's initial request.
Performance Benefits
This architecture provides several key advantages:
- Reduced Latency: Cached content is served instantly without backend requests
- Lower Server Load: Fewer requests to the Drupal backend reduce resource usage
- Improved Scalability: The system can handle more concurrent users efficiently
- Better User Experience: Faster page load times improve user satisfaction
Cache Invalidation
The system includes intelligent cache invalidation mechanisms that automatically clear relevant cache entries when content is updated in Drupal, ensuring users always see the most current content while maintaining optimal performance.