-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Cache warmers are not run after clearing the cache in some scenarios #59445
New issue
8000 Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Just tried your reproducer, and while it’s true your cache warmer runs before the command, I get a If I’m not mistaken such an issue would also impact the |
I believe something called 'clear' should not perform a warmup. I propose creating a new command, |
@MatTheCat is correct. In the first scenario (called "Error" in your reproducer):
This means that in that scenario, the "[OK] Cache for the "dev" environment (debug=true) was successfully cleared." message is incorrect: it didn't have to do anything and didn't do anything. You can verify this works correctly by modifying the custom cache warmer a bit: class CustomCacheWarmer implements CacheWarmerInterface
{
public function warmUp(string $cacheDir, ?string $buildDir = null): array
{
echo "\033[30;44m[DEBUG]\033[0m Running my own custom cache warmer\n";
file_put_contents($cacheDir.'/custom_run', 'Yes!');
return [];
}
// ...
} Despite only seeing the log message once, the |
The code doesn't save things in the cache like this: file_put_contents($cacheDir.'/custom_run', 'Yes!'); It uses Symfony's Cache via a custom cache pool: ->set('cache.easyadmin')
->parent('cache.system')
->tag('cache.pool') And then something like this: use Psr\Cache\CacheItemPoolInterface;
public function __construct(
private CacheItemPoolInterface $cache,
) {
}
$routeNameToFqcnItem = $this->cache->getItem(self::CACHE_KEY_ROUTE_TO_FQCN);
$routeNameToFqcnItem->set($routeNameToFqcn);
$this->cache->save($routeNameToFqcnItem); |
The cache item is removed by the |
#59581 should fix this issue. But @javiereguiluz, please note that making the CacheWarmer of easy-admin non-optional is very likely a mistake. Proof is: this cache-warmer runs before the RouterCacheWarmer, which itself is optional. |
…s-grekas) This PR was merged into the 6.4 branch. Discussion ---------- [Cache] Don't clear system caches on `cache:clear` | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | Fix #59445 | License | MIT As spotted by `@MatTheCat` in #59445 (comment), non-optional cache warmers currently cannot use any cache pools derived from the `cache.system` one. The reason is that when running `cache:clear` with no `var/cache` folder, we skip running those cache warmers since they already ran to execute the command, but we still call the cache clearer service, which empties system pools at the moment, annihilating anything non-optional cache warmers put in these pools. I propose to fix this by just not clearing cache pools derived from the system pool anymore. System pools are meant to we stored in the `kernel.cache_dir` anyway, so they're already cleared when `cache:clear` empties that folder. Commits ------- 8e82056 [Cache] Don't clear system caches on cache:clear
…s-grekas) This PR was merged into the 6.4 branch. Discussion ---------- [Cache] Don't clear system caches on `cache:clear` | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | Fix #59445 | License | MIT As spotted by `@MatTheCat` in symfony/symfony#59445 (comment), non-optional cache warmers currently cannot use any cache pools derived from the `cache.system` one. The reason is that when running `cache:clear` with no `var/cache` folder, we skip running those cache warmers since they already ran to execute the command, but we still call the cache clearer service, which empties system pools at the moment, annihilating anything non-optional cache warmers put in these pools. I propose to fix this by just not clearing cache pools derived from the system pool anymore. System pools are meant to we stored in the `kernel.cache_dir` anyway, so they're already cleared when `cache:clear` empties that folder. Commits ------- 8e820561295 [Cache] Don't clear system caches on cache:clear
Thanks for looking into this. What would you recommend to fix this? Mark the cache warmer as optional? Extend the cache pool not from |
Mark it as non optional yes. This cache warmer is optional. |
Symfony version(s) affected
All
Description
When the cache dirs don't exist (
rm -fr var/cache/*
) if you run the commandbin/console cache:clear
, Symfony runs cache warmers first and then deletes the entire cache (removing all the data created in the cache warmers).If the cache dirs exist, Symfony does the right thing: first it clears the cache and then it runs the cache warmers.
Note: this is not a theoretical edge-case; this is impacting in real-world (see e.g. EasyCorp/EasyAdminBundle#6680)
How to reproduce
I created a small reproducer: https://github.com/javiereguiluz/reproducer
All the details are in the README
The text was updated successfully, but these errors were encountered: