On-demand Cache Revalidation
Performance in Headless architecture relies heavily on aggressive caching. Pyxis CMS ensures the site remains fast (load times <100ms) without serving stale content.
The “Push” Model
Section titled “The “Push” Model”Instead of waiting for cache expiration (TTL), Pyxis CMS implements an instant notification model.
The Workflow
Section titled “The Workflow”- Event: An editor clicks “Publish Changes” in the Filament panel.
- Signal: Laravel sends a POST request to the /api/revalidate endpoint on the frontend.
- Verification: The frontend checks if the secret from the request matches the REVALIDATE_TOKEN in its .env file.
- Purge: The frontend invalidates the cache for the provided path.
Backend Implementation
Section titled “Backend Implementation”Upon publication, the system sends a signal using a shared security token:
Http::post("{$frontendUrl}/api/revalidate", [ 'secret' => env('REVALIDATE_TOKEN'), 'path' => $record->full_url,]);Frontend Requirements
Section titled “Frontend Requirements”Every Pyxis starter (Astro, Next.js) must provide an endpoint that:
- Accepts the POST method.
- Returns a 401 status if tokens do not match.
- Triggers the native cache-clearing function of its framework.