Skip to content

Commit e986621

Browse files
committed
Show correct apcu key size
1 parent 6e8c3dc commit e986621

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/Dashboards/APCu/APCuTrait.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,19 @@ private function moreInfo(): string {
7878
]);
7979
}
8080

81+
private function getKeySize(string $key): int {
82+
$cache_info = apcu_cache_info();
83+
84+
// For some reason apcu_key_info() does not contain the key size
85+
foreach ($cache_info['cache_list'] as $entry) {
86+
if ($entry['info'] === $key) {
87+
return $entry['mem_size'];
88+
}
89+
}
90+
91+
return 0;
92+
}
93+
8194
private function viewKey(): string {
8295
$key = Http::get('key', '');
8396

@@ -108,7 +121,7 @@ private function viewKey(): string {
108121
'key' => $key,
109122
'value' => $formatted_value,
110123
'ttl' => Format::seconds($ttl),
111-
'size' => Format::bytes(strlen($value)),
124+
'size' => Format::bytes($this->getKeySize($key)),
112125
'encode_fn' => $encode_fn,
113126
'formatted' => $is_formatted,
114127
'edit_url' => Http::queryString(['ttl'], ['form' => 'edit', 'key' => $key]),
@@ -184,6 +197,7 @@ private function getAllKeys(): array {
184197
'base64' => true,
185198
'items' => [
186199
'link_title' => $key,
200+
'bytes_size' => $key_data['mem_size'],
187201
'number_hits' => $key_data['num_hits'],
188202
'timediff_last_used' => $key_data['access_time'],
189203
'time_created' => $key_data['creation_time'],

templates/dashboards/apcu.twig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
{{ include('partials/keys_table.twig', {
2020
head_items: [
2121
{'title': 'Key'},
22+
{'title': 'Size', 'class': 'w-16'},
2223
{'title': 'Hits', 'class': 'w-16'},
2324
{'title': 'Last used', 'class': 'w-32'},
2425
{'title': 'Created', 'class': 'w-44 hidden md:table-cell'},

0 commit comments

Comments
 (0)