mikebronner / laravel-model-caching

Eloquent model-caching made easy.
MIT License
2.26k stars 217 forks source link

Caching custom attributes #220

Closed webard closed 5 years ago

webard commented 5 years ago

When Model has a custom attributes like

public function getCanBuyAttribute()
{
        return SOME_HARD_WORK_CALCULATING_CAN_I_BUY_SOMETHING;
}

that attributes are not stored in cache. It is problem when some hard calculations are present in custom attributes methods.

mikebronner commented 5 years ago

This is expected behavior. Only eloquent queries are cached. You would have to return the result of eloquent queries from within the custom attribute for them to be cached. Sorry, this functionality probably won't ever be part of this package, as this package is meant to cache eloquent queries, and not model instances.