mikebronner / laravel-model-caching

Eloquent model-caching made easy.
MIT License
2.23k stars 212 forks source link

Exclude specific models when caching is enabled in BaseModel #396

Closed sburkett closed 3 years ago

sburkett commented 3 years ago

Somewhat self-explanatory, but in short, we have hundreds of models in play. We are currently the BaseModel/use Cachable; approach. It works great! However, there are a handful of models that we don't want to cache. Instead of having to remove the caching trait from the BaseModel and having to add it into hundreds of models, it would be great if we could somehow exclude certain models from being cached.

Could be via some other trait (use NotCacheable) or perhaps an exclusionary array of model names in the config file. Thoughts?

mikebronner commented 3 years ago

Hi @sburkett, thanks for writing in! I believe you should be able to add the following protected property on those models:

protected $isCachable = false;

Let me know how that works for you.

sburkett commented 3 years ago

Works like a champ! Thanks!

mikebronner commented 3 years ago

That's awesome :)