-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[HttpKernel] Add $kernel->getBuildDir()
to separate it from the cache directory
#36515
New issue
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
Conversation
public function getTmpDir() | ||
{ | ||
// Returns $this->getCacheDir() for backward compatibility | ||
return $this->getCacheDir(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is the core of the PR :)
For backward compatibility, I return the current cache directory.
In future versions, this could be for example var/build
. In the meantime, users can override this method to set it to a different path, for example /tmp
.
61bd29e
to
fee57fb
Compare
$kernel->getTmpDir()
to separate it from the cache directory$kernel->getTmpDir()
to separate it from the cache directory
This solution probably makes a lot of sense ... but at first seems confusing: Problem:
Solution:
|
@javiereguiluz yes, this was brought up in #23354 (comment) and I think that's a valid alternative: keep cache as-is, introduce a new I'm waiting for feedback on this new approach, I started looking into it a pull request as well but haven't opened it yet. |
This is a good move IMHO. Reading the related issue, I think we should get the naming right. Keeping the |
$kernel->getTmpDir()
to separate it from the cache directory$kernel->getBuildDir()
to separate it from the cache directory
Great! I have updated the PR. Note that after struggling for a while I did not succeed running the tests locally ( Review is welcome! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM (minor comment)
WDYT @symfony/mergers?
@mnapoli are you using the |
This makes a lot of sense to me. And the fact that the new Very nice! |
if (!is_writable($realCacheDir)) { | ||
throw new RuntimeException(sprintf('Unable to write in the "%s" directory.', $realCacheDir)); | ||
} | ||
|
||
$io->comment(sprintf('Clearing the cache for the <info>%s</info> environment with debug <info>%s</info>', $kernel->getEnvironment(), var_export($kernel->isDebug(), true))); | ||
$this->cacheClearer->clear($realBuildDir); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this command avoid removing the build dir by default? What about adding a --build
option?
For the ones not overriding KernelInterface::getBuildDir()
, this option won't do anything more.
But for the ones overriding, you might want to call this command to clear the read-write cache, but not the read-only build dir, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a first step, we must clear everything like today.
@stof thanks for the tip, I didn't. Still, when I use it the tests crash with:
Anyway, I don't really want to pollute the discussion with this. |
Thank you @mnapoli. |
This PR was merged into the 5.2 branch. Discussion ---------- [FrameworkBundler] Fix cache:clear with buildDir | Q | A | ------------- | --- | Branch? | 5.2 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #39232 | License | MIT | Doc PR | Since #36515 there are 2 caches dir `cacheDir` and `buildDir`. For BC reason both points to the same folders, but when app don't use the same folder, many thing are broken: This PR fixes several issues introduces by the above PR: - some files are persisted in the wrong folder (`App_KernelDevDebugContainerDeprecations.log`, `App_KernelDevDebugContainer.xml`) - LoggerDataCollector looks into cache_dir, while `Compiler.log` is written in build_dir and `Deprecations.log` were written in cache_dir before this PR - the logic that mirror cacheDir into buildDir at the end of CacheClearCommand does not make sens when `cache_dir` and `build_dir` are not identical. - Files generated in cacheDir are trashed at the end of CacheWarming (initial issue) Commits ------- ea68966 Fix cache:clear with buildDir
This PR was squashed before being merged into the 4.x branch. Discussion ---------- Use buildDir for cache Feature available since Symfony 5.2 - symfony/symfony#36515 Commits ------- 9daaade Use buildDir for cache
In order to support deploying on read-only filesystems (e.g. AWS Lambda in my case), I have started implementing #23354.
This introduces
$kernel->getBuildDir()
:$kernel->getBuildDir()
: for cache that can be warmed and deployed as read-only (compiled container, annotations, etc.)$kernel->getCacheDir()
: for cache that can be written at runtime (e.g. cache pools, session, profiler, etc.)I have probably missed some places or some behavior of Symfony that I don't know. Don't consider this PR perfect, but rather I want to help move things forward :)
TODO: