Cache operations
Nwidart\Metrics\Instrumentation\CacheMetrics counts cache operations from Laravel’s cache events. The OpenTelemetry semantic conventions define no cache metric, so the metric and its attributes use the laravel. namespace.
Instrument
Section titled “Instrument”| Property | Value |
|---|---|
| Name | laravel.cache.operations |
| Kind | Counter |
| Unit | {operation} |
| Buckets | None |
| Description | Number of cache operations. |
| Meter | nwidart/laravel-metrics |
| Prometheus name | laravel_cache_operations_total |
Attributes
Section titled “Attributes”| Attribute | Type | Values | Present when |
|---|---|---|---|
laravel.cache.operation |
string | read, write, delete |
Always |
laravel.cache.result |
string | hit or miss for a read, success or failure for a write or a delete |
Always |
laravel.cache.store |
string | The store name from config/cache.php, such as redis |
The event has a store name |
The cache key is never an attribute.
Recorded when
Section titled “Recorded when”| Event | laravel.cache.operation |
laravel.cache.result |
|---|---|---|
Illuminate\Cache\Events\CacheHit |
read |
hit |
Illuminate\Cache\Events\CacheMissed |
read |
miss |
Illuminate\Cache\Events\KeyWritten |
write |
success |
Illuminate\Cache\Events\KeyWriteFailed |
write |
failure |
Illuminate\Cache\Events\KeyForgotten |
delete |
success |
Illuminate\Cache\Events\KeyForgetFailed |
delete |
failure |
Each event adds 1:
many()andputMany()add one per key.remember()adds a read, then a write on a miss.- A failover store records the name of the store that ran the operation.
Not recorded
Section titled “Not recorded”- Operations that dispatch no key event:
increment,decrement, locks, andaddwith a TTL on a store that adds natively (Redis, Memcached, database, DynamoDB, file). flush. Laravel dispatches flush events, and the package does not listen to them.- Operations of a store with
'events' => falseinconfig/cache.php. - Operations of the memoized store (
Cache::memo()). The store under it is counted, on a memo miss. - Reads and writes of the
cachemetrics store. - Durations. The metric is a counter only.
Attribute contributor context
Section titled “Attribute contributor context”A Metrics::attributes() callback for laravel.cache.operations receives the cache event, an Illuminate\Cache\Events\CacheEvent, with $event->key, $event->storeName and $event->tags.
Switch
Section titled “Switch”| Key | Variable | Default |
|---|---|---|
instrumentation.cache |
METRICS_CACHE |
true |