Custom caching of related records doesn't work

I am trying to implement caching of related records, I have two classes, say:

<pre> Car { initialize() { hasMany(Tyre); } }

Tyre { initialize() { belongsTo(Car) } } </pre>

I created a custom cache (Data frontend, File storage) and added it to $di

Now to save related records to this cache, I wrote:

$car = Car::findFirst(); $t = $car->getTyre(); $car->tyre = $t;

// push to cache $cache->save('a-key', $car, 900);

The problem is that the cache only stores Car object. The nested related Tyres are not there

What I am trying to do is very similar to this article -, except that I want to store related records in a custom cache (instead of modelsCache).

Any help would be great! thanks


What you need is intercept the call to getReusableRecords in the models manager and cache the related records: