laravel-eloquent-query-cache icon indicating copy to clipboard operation
laravel-eloquent-query-cache copied to clipboard

On update, cache flush bug

Open shixue opened this issue 1 year ago • 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.

shixue avatar Jan 24 '24 12:01 shixue

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 avatar Jan 24 '24 12:01 shixue

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

kevinlau-drewberry avatar Apr 17 '24 17:04 kevinlau-drewberry