Caching Pages Collections

https://getkirby.com/docs/guide/cache#plugin-caches

is it possible to cache cache pages collections and still be able to use methods on?

so e.g.

  // as demo everthing else from the link above except the 
 //   if ($apiData === null) {
    $apiData = $page->children()->visible();
   // ... 
 // }

While we then later could use all methods with the cache e.g.

  // e.g.
  if($apiData->count()){
      foreach($apiData as $children){
          echo $children->title();
      }
  }

i have been trying to push my luck but always ended with arrays and whatsoever which were obviously not working with the methods, or is there a way to turn the array back to page, without calling it outside of the cache (not by finding via uri or something)

You could use the pages() helper, something like this:

$key = 'whatever your key';
$data = $pluginCache->get($key)['data'];
$collection = pages(array_keys($data));

Where array_keys($data) should give you an array of URIs.

Of course, with all the bells and whistles of checking everything…

thanks, had quite similar stuff without the [‘data’] array addition which wasn’t working.

i changed it a bit further, this helped me and it seems to work now.