Cached collection is returned as an array


Asking here before opening an issue on GitHub, in case that’s the intended behavior and I’m missing something…

I am setting a cached Files index like this:

// $files is a Files object
kirby()->cache('my.plugin')->set('files.index', $files, 15);

When retrieving it later:

// $files is now an array
$files = kirby()->cache('my.plugin')->get('files.index');

Do I have to make it a Files collection again because of some caching pitfall with collections ? Or is it a bug? :thinking:



i think the collection object does not serialize well if one wants to keep all related objects (parent page etc) so only the file uid is stored. you would need the full page index tree otherwise.

but take a look at the autoid modified()-helper which is used to cache collections. it does more than you need and still has the problem of not recognizing all changes but it might get you started.

1 Like