You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/content/docs/digging_deeper/events.md
+115-8Lines changed: 115 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -65,73 +65,180 @@ export interface Emitter {
65
65
66
66
[Emittery](https://github.com/sindresorhus/emittery) is notably a good alternative to Node.js's `EventEmitter` that is compatible with this interface.
67
67
68
-
69
68
## List of Events
70
69
71
70
### `cache:hit`
72
71
73
-
Emitted when a key is found in the cache.
72
+
Emitted when a key is found in the cache.
74
73
75
74
Payload: `{ key, value, store, graced }`
76
75
77
76
-`key`: The key that was found in the cache
78
77
-`value`: The value that was found in the cache
79
78
-`store`: The name of the store that was used to retrieve the value
80
79
-`graced`: `true` when the value was retrieved from a grace period
80
+
81
81
---
82
82
83
83
### `cache:miss`
84
84
85
-
Emitted when a key is not found in the cache.
85
+
Emitted when a key is not found in the cache.
86
86
87
87
Payload: `{ key, store }`
88
88
89
89
-`key`: The key that was not found in the cache
90
90
-`store`: The name of the store that was used to retrieve the value
91
+
91
92
---
92
93
93
94
### `cache:written`
94
95
95
-
Emitted when a key is written to the cache.
96
+
Emitted when a key is written to the cache.
96
97
97
98
Payload: `{ key, value, store }`
98
99
99
100
-`key`: The key that was written to the cache
100
101
-`value`: The value that was written to the cache
102
+
101
103
---
102
104
103
105
### `cache:deleted`
104
106
105
-
Emitted when the key is removed from the cache.
107
+
Emitted when the key is removed from the cache.
106
108
107
109
Payload: `{ key, store }`
108
110
109
111
-`key`: The key that was removed from the cache
110
112
-`store`: The name of the store that was used to remove the value
113
+
111
114
---
112
115
113
116
### `cache:cleared`
114
117
115
-
Emitted when the cache is emptied.
118
+
Emitted when the cache is emptied.
116
119
117
120
Payload: `{ store }`
118
121
119
122
-`store`: The name of the store that was emptied
123
+
120
124
---
121
125
122
126
### `bus:message:published`
123
127
124
-
Emitted when the bus publishes a message to other applications.
128
+
Emitted when the bus publishes a message to other applications.
125
129
126
130
Payload: `{ message }`
127
131
128
132
-`message`: The message that was published
133
+
129
134
---
130
135
131
136
### `bus:message:received`
132
137
133
-
Emitted when the application receives a message instructing it to update its cache.
138
+
Emitted when the application receives a message instructing it to update its cache.
134
139
135
140
Payload: `{ message }`
136
141
137
142
-`message`: The message that was received
143
+
144
+
---
145
+
146
+
## Tracing Channels (Experimental)
147
+
148
+
:::warning
149
+
This API is experimental and may change in future versions.
150
+
:::
151
+
152
+
Bentocache also exposes [Node.js Diagnostic Channels](https://nodejs.org/api/diagnostics_channel.html#tracingchannel) for more advanced instrumentation needs. Unlike events, tracing channels provide timing information and are designed for APM tools and OpenTelemetry integration.
153
+
154
+
### Why Tracing Channels?
155
+
156
+
-**Built-in**: No external dependencies, uses Node.js native `diagnostics_channel`
157
+
-**Zero overhead**: When no subscribers are attached, there's virtually no performance impact
158
+
-**Timing information**: Automatically tracks start/end of async operations
159
+
-**APM integration**: Works seamlessly with OpenTelemetry and other APM tools
160
+
161
+
### Available Channels
162
+
163
+
#### `bentocache.cache.operation`
164
+
165
+
Traces all cache operations with timing information.
166
+
167
+
```ts
168
+
import { tracingChannels } from'bentocache'
169
+
170
+
tracingChannels.cacheOperation.subscribe({
171
+
start(message) {
172
+
// Called when operation starts
173
+
console.log(`Starting ${message.operation} on ${message.key}`)
0 commit comments