@@ -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 ' ],
0 commit comments