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 - http://docs.phalconphp.com/en/latest/reference/models-cache.html#caching-related-records-recursively, except that I want to store related records in a custom cache (instead of modelsCache).

Any help would be great! thanks



83.4k

What you need is intercept the call to getReusableRecords in the models manager and cache the related records: http://docs.phalconphp.com/en/latest/reference/models-cache.html#reusable-related-records