Commit 7bd849c
authored
Get cache tags once when invalidating
I'm using an overridden `getCacheTagsToInvalidateOnUpdate()` to track how many times each tag is invalidated. The way `invalidateCache()` was originally written calls the `getCacheTagsToInvalidateOnUpdate()` method twice, resulting in the tags being counted twice for each invalidation. This change simply assigns the tags to a variable and uses the variable instead of calling the method directly.
FWIW, this is what I'm doing to track the tag invalidations. Just a simple array saved to the cache.
```php
public function getCacheTagsToInvalidateOnUpdate($relation = null, $pivotedModels = null): array
{
$tags = $this->getCacheBaseTags();
$invalidations = Cache::get('cache-invalidations', []);
foreach ($tags as $tag) {
$invalidations[$tag] = ($invalidations[$tag] ?? 0) + 1;
}
Cache::forever('cache-invalidations', $invalidations);
return $tags;
}
```1 parent 7e77875 commit 7bd849c
1 file changed
+4
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
154 | 154 | | |
155 | 155 | | |
156 | 156 | | |
157 | | - | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
158 | 160 | | |
159 | 161 | | |
160 | 162 | | |
161 | | - | |
162 | | - | |
163 | | - | |
| 163 | + | |
164 | 164 | | |
165 | 165 | | |
0 commit comments