renoki-co/laravel-eloquent-query-cache

On update, cache flush bug

shixue opened this issue · 2 comments

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.

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.

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