Advanced Guides
Caching
Several Autoload routes are lined with multiple instances of caching.
Should Cache?
In Auto, we have a few checks in place before most of the caching is resolved. We do this in an effort not to cache invalid or inactive data; primarily "inactive"/unpublished Pages. This "Should Cache" check has 5main parts:
- Is the given Request URL cacheable?
- Does the given Request have flash/session data in it?
- Does the Request have special Autoload headers?
- Is the Request a Page and is that Page "active"/published?
- Does the page not have any Livewire components on them? (we don't want to cache Livewire)
If any of those 5 parts returns false
, then that given Request will not be cached.
Cache Types
There are 3 different types of Caching that is used across Autoload.
Laravel Cache
In an effort to reduce repeated database queries, if a Page is found on an incoming request, we will cache the underlying Page Model into Laravel's flat-file cache system. So that on subsequent requests, instead of querying the database, we'll look for that Page within the flat-file cache system instead. This cache is not behind the "Should Cache" check.
Response Cache
We use Spatie's Response Cache package to also speed up subsequent requests to the same resource. This cache is behind the "Should Cache" check.
Static Cache
Lastly, we use a modified version of a community package called Page Cache for saving a rendered Page into an HTML file.
This takes a given Page response and saves it to a flat HTML file within Laravel's /public
directory,
meaning that Page's content can now be accessed without ever hitting the Laravel application at all.
There are several modifications that need to be in place for this Page Cache to work correctly, check out the Deployment documentation for more information.
Clearing the Cache
Manual
To force clear the entire Autoload cache; including Laravel Cache, Response Cache, and Static Cache, you will need to be logged into that site's CMS.
From the Dashboard, there is a System Cache "card" available with a red button that says "Clear All Cache." Pressing that button will reset the entire cache.
This will only clear the cache, this will not re-cache any Pages.
Automatic
All Autoload Models that use these Cache types also have callback "hooks" built in that will automatically clear when a Model is updated/deleted. For instance, if a Page is already cached and someone adds a new Content Block through the CMS, upon saving the changes, Autoload will automatically clear the cache for that specific Page only and then re-cache it with the new information.