88
99namespace RobiNN \Pca \Dashboards \APCu ;
1010
11+ use APCUIterator ;
1112use RobiNN \Pca \Config ;
1213use RobiNN \Pca \Format ;
1314use RobiNN \Pca \Helpers ;
@@ -185,30 +186,30 @@ public function getAllKeys(): array {
185186 $ search = Http::get ('s ' , '' );
186187 $ this ->template ->addGlobal ('search_value ' , $ search );
187188
188- $ info = apcu_cache_info ();
189189 $ keys = [];
190190 $ time = time ();
191191
192- foreach ($ info ['cache_list ' ] as $ key_data ) {
193- $ key = $ key_data ['info ' ];
194-
195- if (stripos ($ key , $ search ) !== false ) {
196- $ keys [] = [
197- 'key ' => $ key ,
198- 'mem_size ' => $ key_data ['mem_size ' ],
199- 'num_hits ' => $ key_data ['num_hits ' ],
200- 'access_time ' => $ key_data ['access_time ' ],
201- 'creation_time ' => $ key_data ['creation_time ' ],
202- 'ttl ' => $ key_data ['ttl ' ] === 0 ? 'Doesn \'t expire ' : $ key_data ['creation_time ' ] + $ key_data ['ttl ' ] - $ time ,
203- ];
192+ $ iterator = new APCUIterator ('/.*/ ' , APC_ITER_ALL , 0 , APC_LIST_ACTIVE );
193+
194+ foreach ($ iterator as $ item ) {
195+ $ key = $ item ['key ' ];
196+
197+ if ($ search !== '' && stripos ($ key , $ search ) === false ) {
198+ continue ;
204199 }
205- }
206200
207- if (Http::get ('view ' , Config::get ('list-view ' , 'table ' )) === 'tree ' ) {
208- return $ this ->keysTreeView ($ keys );
201+ $ ttl = $ item ['ttl ' ];
202+ $ keys [] = [
203+ 'key ' => $ key ,
204+ 'mem_size ' => $ item ['mem_size ' ] ?? 0 ,
205+ 'num_hits ' => $ item ['num_hits ' ] ?? 0 ,
206+ 'access_time ' => $ item ['access_time ' ] ?? 0 ,
207+ 'creation_time ' => $ item ['creation_time ' ] ?? 0 ,
208+ 'ttl ' => $ ttl === 0 ? 'Doesn \'t expire ' : ($ item ['creation_time ' ] + $ ttl - $ time ),
209+ ];
209210 }
210211
211- return $ this -> keysTableView ( $ keys) ;
212+ return $ keys ;
212213 }
213214
214215 /**
@@ -295,8 +296,6 @@ private function keysTreeView(array $keys): array {
295296 }
296297
297298 private function mainDashboard (): string {
298- $ keys = $ this ->getAllKeys ();
299-
300299 if (isset ($ _POST ['submit_import_key ' ])) {
301300 Helpers::import (
302301 static fn (string $ key ): bool => apcu_exists ($ key ),
@@ -306,16 +305,29 @@ static function (string $key, string $value, int $ttl): bool {
306305 );
307306 }
308307
308+ $ keys = $ this ->getAllKeys ();
309+
309310 if (isset ($ _GET ['export_btn ' ])) {
310311 Helpers::export ($ keys , 'apcu_backup ' , static fn (string $ key ): string => base64_encode (serialize (apcu_fetch ($ key ))));
311312 }
312313
313314 $ paginator = new Paginator ($ this ->template , $ keys );
315+ $ paginated_keys = $ paginator ->getPaginated ();
316+
317+
318+
319+ if (Http::get ('view ' , Config::get ('list-view ' , 'table ' )) === 'tree ' ) {
320+ $ keys_to_display = $ this ->keysTreeView ($ paginated_keys );
321+ } else {
322+ $ keys_to_display = $ this ->keysTableView ($ paginated_keys );
323+ }
324+
325+ unset($ keys , $ paginated_keys );
314326
315327 $ info = apcu_cache_info (true );
316328
317329 return $ this ->template ->render ('dashboards/apcu ' , [
318- 'keys ' => $ paginator -> getPaginated () ,
330+ 'keys ' => $ keys_to_display ,
319331 'all_keys ' => (int ) $ info ['num_entries ' ],
320332 'paginator ' => $ paginator ->render (),
321333 'view_key ' => Http::queryString ([], ['view ' => 'key ' , 'key ' => '__key__ ' ]),
0 commit comments