How to invalidate a specific model ID ?
t-prod opened this issue · 3 comments
t-prod commented
Hi,
Thanks for your awesome package. I need to invalidate cache for specific model ID (and its relationship). How can I do that ?
Thanks for your help.
Cyril
henriquetroiano commented
The default observer from models can detect changes and invalidade the cache.
But do you have tried with laravel ->refresh() method ?
If keep not working, here it is the function used for invalidate the cache:
/**
* Invalidate the cache for a model.
*
* @param \Illuminate\Database\Eloquent\Model $model
* @param string|null $relation
* @param \Illuminate\Database\Eloquent\Collection|null $pivotedModels
* @return void
*
* @throws Exception
*/
protected function invalidateCache(Model $model, $relation = null, $pivotedModels = null): void
{
$class = get_class($model);
$tags = $model->getCacheTagsToInvalidateOnUpdate($relation, $pivotedModels);
if (!$tags) {
throw new Exception('Automatic invalidation for ' . $class . ' works only if at least one tag to be invalidated is specified.');
}
$class::flushQueryCache($tags);
}
t-prod commented
Thanks again for your help. You mean that a simple $model->refresh() can do the job ?
How can you do for a specifite route or URL to invalidate the cache ?
For instance /admin ?
stale commented
This issue has been automatically closed because it has not had any recent activity. 😨