Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ab54d0c

Browse filesBrowse files
Don't enable tracing unless the profiler is enabled
1 parent 6dd4353 commit ab54d0c
Copy full SHA for ab54d0c

File tree

3 files changed

+43
-3
lines changed
Filter options

3 files changed

+43
-3
lines changed

‎Adapter/TraceableAdapter.php

Copy file name to clipboardExpand all lines: Adapter/TraceableAdapter.php
+37
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class TraceableAdapter implements AdapterInterface, CacheInterface, NamespacedPo
3434

3535
public function __construct(
3636
protected AdapterInterface $pool,
37+
protected readonly ?\Closure $disabled = null,
3738
) {
3839
}
3940

@@ -45,6 +46,9 @@ public function get(string $key, callable $callback, ?float $beta = null, ?array
4546
if (!$this->pool instanceof CacheInterface) {
4647
throw new BadMethodCallException(\sprintf('Cannot call "%s::get()": this class doesn\'t implement "%s".', get_debug_type($this->pool), CacheInterface::class));
4748
}
49+
if ($this->disabled?->__invoke()) {
50+
return $this->pool->get($key, $callback, $beta, $metadata);
51+
}
4852

4953
$isHit = true;
5054
$callback = function (CacheItem $item, bool &$save) use ($callback, &$isHit) {
@@ -71,6 +75,9 @@ public function get(string $key, callable $callback, ?float $beta = null, ?array
7175

7276
public function getItem(mixed $key): CacheItem
7377
{
78+
if ($this->disabled?->__invoke()) {
79+
return $this->pool->getItem($key);
80+
}
7481
$event = $this->start(__FUNCTION__);
7582
try {
7683
$item = $this->pool->getItem($key);
@@ -88,6 +95,9 @@ public function getItem(mixed $key): CacheItem
8895

8996
public function hasItem(mixed $key): bool
9097
{
98+
if ($this->disabled?->__invoke()) {
99+
return $this->pool->hasItem($key);
100+
}
91101
$event = $this->start(__FUNCTION__);
92102
try {
93103
return $event->result[$key] = $this->pool->hasItem($key);
@@ -98,6 +108,9 @@ public function hasItem(mixed $key): bool
98108

99109
public function deleteItem(mixed $key): bool
100110
{
111+
if ($this->disabled?->__invoke()) {
112+
return $this->pool->deleteItem($key);
113+
}
101114
$event = $this->start(__FUNCTION__);
102115
try {
103116
return $event->result[$key] = $this->pool->deleteItem($key);
@@ -108,6 +121,9 @@ public function deleteItem(mixed $key): bool
108121

109122
public function save(CacheItemInterface $item): bool
110123
{
124+
if ($this->disabled?->__invoke()) {
125+
return $this->pool->save($item);
126+
}
111127
$event = $this->start(__FUNCTION__);
112128
try {
113129
return $event->result[$item->getKey()] = $this->pool->save($item);
@@ -118,6 +134,9 @@ public function save(CacheItemInterface $item): bool
118134

119135
public function saveDeferred(CacheItemInterface $item): bool
120136
{
137+
if ($this->disabled?->__invoke()) {
138+
return $this->pool->saveDeferred($item);
139+
}
121140
$event = $this->start(__FUNCTION__);
122141
try {
123142
return $event->result[$item->getKey()] = $this->pool->saveDeferred($item);
@@ -128,6 +147,9 @@ public function saveDeferred(CacheItemInterface $item): bool
128147

129148
public function getItems(array $keys = []): iterable
130149
{
150+
if ($this->disabled?->__invoke()) {
151+
return $this->pool->getItems($keys);
152+
}
131153
$event = $this->start(__FUNCTION__);
132154
try {
133155
$result = $this->pool->getItems($keys);
@@ -151,6 +173,9 @@ public function getItems(array $keys = []): iterable
151173

152174
public function clear(string $prefix = ''): bool
153175
{
176+
if ($this->disabled?->__invoke()) {
177+
return $this->pool->clear($prefix);
178+
}
154179
$event = $this->start(__FUNCTION__);
155180
try {
156181
if ($this->pool instanceof AdapterInterface) {
@@ -165,6 +190,9 @@ public function clear(string $prefix = ''): bool
165190

166191
public function deleteItems(array $keys): bool
167192
{
193+
if ($this->disabled?->__invoke()) {
194+
return $this->pool->deleteItems($keys);
195+
}
168196
$event = $this->start(__FUNCTION__);
169197
$event->result['keys'] = $keys;
170198
try {
@@ -176,6 +204,9 @@ public function deleteItems(array $keys): bool
176204

177205
public function commit(): bool
178206
{
207+
if ($this->disabled?->__invoke()) {
208+
return $this->pool->commit();
209+
}
179210
$event = $this->start(__FUNCTION__);
180211
try {
181212
return $event->result = $this->pool->commit();
@@ -189,6 +220,9 @@ public function prune(): bool
189220
if (!$this->pool instanceof PruneableInterface) {
190221
return false;
191222
}
223+
if ($this->disabled?->__invoke()) {
224+
return $this->pool->prune();
225+
}
192226
$event = $this->start(__FUNCTION__);
193227
try {
194228
return $event->result = $this->pool->prune();
@@ -208,6 +242,9 @@ public function reset(): void
208242

209243
public function delete(string $key): bool
210244
{
245+
if ($this->disabled?->__invoke()) {
246+
return $this->pool->deleteItem($key);
247+
}
211248
$event = $this->start(__FUNCTION__);
212249
try {
213250
return $event->result[$key] = $this->pool->deleteItem($key);

‎Adapter/TraceableTagAwareAdapter.php

Copy file name to clipboardExpand all lines: Adapter/TraceableTagAwareAdapter.php
+5-2
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,16 @@
1818
*/
1919
class TraceableTagAwareAdapter extends TraceableAdapter implements TagAwareAdapterInterface, TagAwareCacheInterface
2020
{
21-
public function __construct(TagAwareAdapterInterface $pool)
21+
public function __construct(TagAwareAdapterInterface $pool, ?\Closure $disabled = null)
2222
{
23-
parent::__construct($pool);
23+
parent::__construct($pool, $disabled);
2424
}
2525

2626
public function invalidateTags(array $tags): bool
2727
{
28+
if ($this->disabled?->__invoke()) {
29+
return $this->pool->invalidateTags($tags);
30+
}
2831
$event = $this->start(__FUNCTION__);
2932
try {
3033
return $event->result = $this->pool->invalidateTags($tags);

‎DependencyInjection/CacheCollectorPass.php

Copy file name to clipboardExpand all lines: DependencyInjection/CacheCollectorPass.php
+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ private function addToCollector(string $id, string $name, ContainerBuilder $cont
5252
if (!$definition->isPublic() || !$definition->isPrivate()) {
5353
$recorder->setPublic($definition->isPublic());
5454
}
55-
$recorder->setArguments([new Reference($innerId = $id.'.recorder_inner')]);
55+
$recorder->setArguments([new Reference($innerId = $id.'.recorder_inner'), new Reference('profiler.is_disabled_state_checker', ContainerBuilder::IGNORE_ON_INVALID_REFERENCE)]);
5656

5757
foreach ($definition->getMethodCalls() as [$method, $args]) {
5858
if ('setCallbackWrapper' !== $method || !$args[0] instanceof Definition || !($args[0]->getArguments()[2] ?? null) instanceof Definition) {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.