Cache events
An application can use a cache to store data that is expensive to compute. Flare can collect information about the cache events in your application.
Flare will collect the following information:
- The cache key
- The cache store
- The cache operation (
Get,Set,Forget) - The cache result (
Hit,Miss,Success,Failure)
This functionality is enabled by default, but you can disable it by ignoring the Cache collect in config.php:
use Spatie\FlareClient\Enums\CollectType;
'collects' => FlareConfig::defaultCollects(
ignore: [CollectType::Cache],
),
It is possible to limit the amount of cache events tracked while collecting data in the case of an error, as such:
'collects' => FlareConfig::defaultCollects(
extra: [
CollectType::Cache->value => [
'max_items_with_errors' => 50,
],
]
),
It is possible to limit the types of cache operations that are collected:
use Spatie\FlareClient\Enums\CacheOperation;
'collects' => FlareConfig::defaultCollects(
extra: [
CollectType::Cache->value => [
'operations' => [CacheOperation::Get]
],
]
),
Ignoring cache keys
Some cache keys are noise you never want to see in Flare. You can skip cache events by matching their key against a list of patterns:
'collects' => FlareConfig::defaultCollects(
extra: [
CollectType::Cache->value => [
'ignored_keys' => ['/^my-app:internal:/'],
],
]
),
Each pattern is a regular expression including its delimiters, so /^my-app:internal:/ skips every key starting with my-app:internal:. These are not glob patterns, unlike the ignore options for requests and routes.
The keys you configure are added to a list Flare already ignores, they do not replace it. Out of the box, the Laravel package skips:
- Laravel internals, meaning every key prefixed with
illuminate: - The scheduler, which stores its state under
framework/schedule - Vapor job attempt counters
- Pulse
- Reverb
- Horizon
- Nova
- Telescope
- Livewire checksum failures
One exception to the illuminate: rule is Cache::flexible(). It writes a marker key under illuminate:cache:flexible:created: followed by your own cache key. Flare keeps those events, because they describe your cache activity rather than framework noise.
Manually recording cache events
If you're interacting with a cache that isn't managed by Laravel's cache system, you can record events manually. The PHP documentation provides a full overview of all available recorder methods. When using these methods in Laravel, use the Flare facade instead of $flare:
use Spatie\LaravelFlare\Facades\Flare;
use Spatie\FlareClient\Enums\CacheOperation;
use Spatie\FlareClient\Enums\CacheResult;
Flare::cache()->record(
key: 'my-key',
store: 'redis',
operation: CacheOperation::Get,
result: CacheResult::Hit,
);
On this page