@@ -34,6 +34,7 @@ class TraceableAdapter implements AdapterInterface, CacheInterface, NamespacedPo
34
34
35
35
public function __construct (
36
36
protected AdapterInterface $ pool ,
37
+ protected readonly ?\Closure $ disabled = null ,
37
38
) {
38
39
}
39
40
@@ -45,6 +46,9 @@ public function get(string $key, callable $callback, ?float $beta = null, ?array
45
46
if (!$ this ->pool instanceof CacheInterface) {
46
47
throw new BadMethodCallException (\sprintf ('Cannot call "%s::get()": this class doesn \'t implement "%s". ' , get_debug_type ($ this ->pool ), CacheInterface::class));
47
48
}
49
+ if ($ this ->disabled ?->__invoke()) {
50
+ return $ this ->pool ->get ($ key , $ callback , $ beta , $ metadata );
51
+ }
48
52
49
53
$ isHit = true ;
50
54
$ callback = function (CacheItem $ item , bool &$ save ) use ($ callback , &$ isHit ) {
@@ -71,6 +75,9 @@ public function get(string $key, callable $callback, ?float $beta = null, ?array
71
75
72
76
public function getItem (mixed $ key ): CacheItem
73
77
{
78
+ if ($ this ->disabled ?->__invoke()) {
79
+ return $ this ->pool ->getItem ($ key );
80
+ }
74
81
$ event = $ this ->start (__FUNCTION__ );
75
82
try {
76
83
$ item = $ this ->pool ->getItem ($ key );
@@ -88,6 +95,9 @@ public function getItem(mixed $key): CacheItem
88
95
89
96
public function hasItem (mixed $ key ): bool
90
97
{
98
+ if ($ this ->disabled ?->__invoke()) {
99
+ return $ this ->pool ->hasItem ($ key );
100
+ }
91
101
$ event = $ this ->start (__FUNCTION__ );
92
102
try {
93
103
return $ event ->result [$ key ] = $ this ->pool ->hasItem ($ key );
@@ -98,6 +108,9 @@ public function hasItem(mixed $key): bool
98
108
99
109
public function deleteItem (mixed $ key ): bool
100
110
{
111
+ if ($ this ->disabled ?->__invoke()) {
112
+ return $ this ->pool ->deleteItem ($ key );
113
+ }
101
114
$ event = $ this ->start (__FUNCTION__ );
102
115
try {
103
116
return $ event ->result [$ key ] = $ this ->pool ->deleteItem ($ key );
@@ -108,6 +121,9 @@ public function deleteItem(mixed $key): bool
108
121
109
122
public function save (CacheItemInterface $ item ): bool
110
123
{
124
+ if ($ this ->disabled ?->__invoke()) {
125
+ return $ this ->pool ->save ($ item );
126
+ }
111
127
$ event = $ this ->start (__FUNCTION__ );
112
128
try {
113
129
return $ event ->result [$ item ->getKey ()] = $ this ->pool ->save ($ item );
@@ -118,6 +134,9 @@ public function save(CacheItemInterface $item): bool
118
134
119
135
public function saveDeferred (CacheItemInterface $ item ): bool
120
136
{
137
+ if ($ this ->disabled ?->__invoke()) {
138
+ return $ this ->pool ->saveDeferred ($ item );
139
+ }
121
140
$ event = $ this ->start (__FUNCTION__ );
122
141
try {
123
142
return $ event ->result [$ item ->getKey ()] = $ this ->pool ->saveDeferred ($ item );
@@ -128,6 +147,9 @@ public function saveDeferred(CacheItemInterface $item): bool
128
147
129
148
public function getItems (array $ keys = []): iterable
130
149
{
150
+ if ($ this ->disabled ?->__invoke()) {
151
+ return $ this ->pool ->getItems ($ keys );
152
+ }
131
153
$ event = $ this ->start (__FUNCTION__ );
132
154
try {
133
155
$ result = $ this ->pool ->getItems ($ keys );
@@ -151,6 +173,9 @@ public function getItems(array $keys = []): iterable
151
173
152
174
public function clear (string $ prefix = '' ): bool
153
175
{
176
+ if ($ this ->disabled ?->__invoke()) {
177
+ return $ this ->pool ->clear ($ prefix );
178
+ }
154
179
$ event = $ this ->start (__FUNCTION__ );
155
180
try {
156
181
if ($ this ->pool instanceof AdapterInterface) {
@@ -165,6 +190,9 @@ public function clear(string $prefix = ''): bool
165
190
166
191
public function deleteItems (array $ keys ): bool
167
192
{
193
+ if ($ this ->disabled ?->__invoke()) {
194
+ return $ this ->pool ->deleteItems ($ keys );
195
+ }
168
196
$ event = $ this ->start (__FUNCTION__ );
169
197
$ event ->result ['keys ' ] = $ keys ;
170
198
try {
@@ -176,6 +204,9 @@ public function deleteItems(array $keys): bool
176
204
177
205
public function commit (): bool
178
206
{
207
+ if ($ this ->disabled ?->__invoke()) {
208
+ return $ this ->pool ->commit ();
209
+ }
179
210
$ event = $ this ->start (__FUNCTION__ );
180
211
try {
181
212
return $ event ->result = $ this ->pool ->commit ();
@@ -189,6 +220,9 @@ public function prune(): bool
189
220
if (!$ this ->pool instanceof PruneableInterface) {
190
221
return false ;
191
222
}
223
+ if ($ this ->disabled ?->__invoke()) {
224
+ return $ this ->pool ->prune ();
225
+ }
192
226
$ event = $ this ->start (__FUNCTION__ );
193
227
try {
194
228
return $ event ->result = $ this ->pool ->prune ();
@@ -208,6 +242,9 @@ public function reset(): void
208
242
209
243
public function delete (string $ key ): bool
210
244
{
245
+ if ($ this ->disabled ?->__invoke()) {
246
+ return $ this ->pool ->deleteItem ($ key );
247
+ }
211
248
$ event = $ this ->start (__FUNCTION__ );
212
249
try {
213
250
return $ event ->result [$ key ] = $ this ->pool ->deleteItem ($ key );
0 commit comments