Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 18 additions & 10 deletions src/DataCollector/CacheCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@

use DebugBar\DataCollector\TimeDataCollector;
use DebugBar\DataFormatter\HasDataFormatter;
use Illuminate\Cache\Events\CacheEvent;
use Illuminate\Cache\Events\CacheHit;
use Illuminate\Cache\Events\CacheMissed;
use Illuminate\Cache\Events\KeyForgotten;
use Illuminate\Cache\Events\KeyWritten;
use Illuminate\Cache\Events\{
CacheFlushed,
CacheFlushFailed,
CacheHit,
CacheMissed,
KeyForgetFailed,
KeyForgotten,
KeyWriteFailed,
KeyWritten,
};
use Illuminate\Events\Dispatcher;

class CacheCollector extends TimeDataCollector
Expand All @@ -22,8 +27,12 @@ class CacheCollector extends TimeDataCollector
protected $classMap = [
CacheHit::class => 'hit',
CacheMissed::class => 'missed',
CacheFlushed::class => 'flushed',
CacheFlushFailed::class => 'flush_failed',
KeyWritten::class => 'written',
KeyWriteFailed::class => 'write_failed',
KeyForgotten::class => 'forgotten',
KeyForgetFailed::class => 'forget_failed',
];

public function __construct($requestStartTime, $collectValues)
Expand All @@ -33,7 +42,7 @@ public function __construct($requestStartTime, $collectValues)
$this->collectValues = $collectValues;
}

public function onCacheEvent(CacheEvent $event)
public function onCacheEvent($event)
{
$class = get_class($event);
$params = get_object_vars($event);
Expand All @@ -53,21 +62,20 @@ public function onCacheEvent(CacheEvent $event)
}


if (!empty($params['key']) && in_array($label, ['hit', 'written'])) {
if (!empty($params['key'] ?? null) && in_array($label, ['hit', 'written'])) {
$params['delete'] = route('debugbar.cache.delete', [
'key' => urlencode($params['key']),
'tags' => !empty($params['tags']) ? json_encode($params['tags']) : '',
]);
}

$time = microtime(true);
$this->addMeasure($label . "\t" . $event->key, $time, $time, $params);
$this->addMeasure($label . "\t" . ($params['key'] ?? ''), $time, $time, $params);
}


public function subscribe(Dispatcher $dispatcher)
{
foreach ($this->classMap as $eventClass => $type) {
foreach (array_keys($this->classMap) as $eventClass) {
$dispatcher->listen($eventClass, [$this, 'onCacheEvent']);
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/Resources/cache/widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
var m = lines[i];

if (measure.params && !$.isEmptyObject(measure.params)) {
if (measure.params.delete) {
$(m).next().find('td.phpdebugbar-widgets-name:contains(delete)').closest('tr').remove();
}
if (measure.params.delete && measure.params.key) {
$('<a />')
.addClass(csscls('forget'))
Expand Down
Loading