mikebronner / laravel-model-caching

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

Correct approach for invalidating partial models #414

Closed lgrassini closed 2 years ago

lgrassini commented 2 years ago

Issue

I'm looking for a solution to invalidate cache for certain records and not for the entire model. Our scenario is the following: We have a Site entity handling thousands of websites using the Site model (and related models). We would like to be able to clear cache for a particular website and not for all the other websites cached with modelCache.

I can't found any instructions for doing this in the modelCache documentation.

How can we achieve this?

Environment

Laravel Version: 8.70.2 Laravel Model Caching Package Version: 0.10.3 PHP Version: 7.4.26 Operating System & Version: macOS 12.0.1

mikebronner commented 2 years ago

Hi @lgrassini, thanks for writing in. Unfortunately that is not possible with this package, as this package caches the eloquent queries, not the models themselves.

lgrassini commented 2 years ago

So when we execute artisan modelCache:clear --model=App\SomeModelName what are we clearing? a model or eloquent queries?

mikebronner commented 2 years ago

@lgrassini that clears all the cached eloquent queries that use that model.