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 (
CacheOperation::Get,CacheOperation::Set,CacheOperation::Forget) - The cache result (
CacheResult::Hit,CacheResult::Miss,CacheResult::Sucess,CacheResult::Failure)
It is possible to disable this behaviour by ignoring cache events in the Flare config:
$config->ignoreCacheEvents();
The amount of cache events tracked while collecting data in the case of an error can be configured as such:
$config->collectCacheEvents(maxItemsWithErrors: 50);
It is also possible to limit the types of cache operations that are collected:
$config->collectCacheEvents(
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:
$config->collectCacheEvents(
ignoredKeys: [
'/^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.
In this framework-agnostic client, nothing is ignored by default. Framework adapters can add their own defaults on top of the keys you configure, and both lists always apply. The Laravel package, for example, ignores a set of framework and vendor keys out of the box.
Collecting cache events
We cannot automatically collect cache events in the framework-agnostic version of the package. You can manually add cache events as such:
use Spatie\FlareClient\Enums\CacheOperation;
use Spatie\FlareClient\Enums\CacheResult;
$flare->cache()->record(
key: 'my-key',
store: 'redis',
operation: CacheOperation::Get,
result: CacheResult::Hit,
);
The following combinations of operations and results are possible:
| Operation | Result |
|---|---|
CacheOperation::Get |
CacheResult::Hit |
CacheOperation::Get |
CacheResult::Miss |
CacheOperation::Set |
CacheResult::Success |
CacheOperation::Set |
CacheResult::Failure |
CacheOperation::Forget |
CacheResult::Success |
CacheOperation::Forget |
CacheResult::Failure |
It is possible to add extra attributes to a cache event as such:
$flare->cache()->record(
key: 'my-key',
store: 'redis',
operation: CacheOperation::Get,
result: CacheResult::Hit,
attributes: [
'cache.value' => $value,
]
);
On this page