renoki-co / laravel-eloquent-query-cache

Adding cache on your Laravel Eloquent queries' results is now a breeze.
Apache License 2.0
1.04k stars 108 forks source link

On update, cache flush bug #209

Open shixue opened 7 months ago

shixue commented 7 months ago

The cause of this bug (issues #97) : QueryCacheable:

public function getCacheTagsToInvalidateOnUpdate($relation = null, $pivotedModels = null): array
{
    return $this->getCacheBaseTags();
}

Example:

User::cacheTags(['user:29'])->find(29);
$userId = 28;
$model = User::cacheTags(['user:' . $userId])->find($userId);
//...
$model->update(['ip' => $ip]);

When specifying the cacheTags getCacheTagsToInvalidateOnUpdate() method should return it. All that is returned so far is getCacheBaseTags(), the cached updated tags are static::class, not the specified tags. Just like the flushQueryCache() method, use it if tags are specified, otherwise use the getCacheBaseTags() method.

shixue commented 7 months ago

Tags can be added to the Model after the queried. getCacheTagsToInvalidateOnUpdate() method to obtain the Model of the specified Tags, if the Model exists to specify Tags.

kevinlau-drewberry commented 4 months ago

@shixue would you mind explaining how to add tags after a query is made?