-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
Fix loss of page_cache cache_dir setting from di.xml #22228
Fix loss of page_cache cache_dir setting from di.xml #22228
Conversation
Hi @Vinai. Thank you for your contribution
For more details, please, review the Magento Contributor Assistant documentation |
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.
Steps for quality:
- ✅ Review please see comments
- ❗️ Travis build
- ❗️ Manual Testing
dev/tests/integration/testsuite/Magento/Framework/App/Cache/Frontend/PoolTest.php
Show resolved
Hide resolved
|
||
$this->assertSame($testData, $pageCache->load($testKey)); | ||
} | ||
} |
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.
Empty Line missing
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.
Fixed. But I'm curious what is the reason for this rule? It seems very arbitrary and useless to me...
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.
@larsroettig didn't get which line you talked about...
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.
Before I changed the commit line 59 was missing.
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.
@Vinai I don't think it's needed. Basically any missing line is not worth commenting - phpcs should catch all needed.
dev/tests/integration/testsuite/Magento/Framework/App/Cache/Frontend/PoolTest.php
Show resolved
Hide resolved
dev/tests/integration/testsuite/Magento/Framework/App/Cache/Frontend/PoolTest.php
Show resolved
Hide resolved
Thanks for the review @larsroettig, sorry for being a little bitter sometimes. I really do appreciate you taking the time to look it over 👍 |
The Codacy warnings are related only to outdated rule names in the ruleset:
|
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.
Thanks @Vinai!
Codacy can be completely ignored, I heard about plans to turn it off but not sure why it's still here.
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* This is prime example for a senseless comment that only exists to satisfy the coding standard. |
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.
I feel your pain, this is one of mine top priorities in phpcs-related stuff, annoys me since @return void
was introduced.
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.
unfortunately Magento code is there for everybody to see and interpret and we have to do yet better, meaningful, rhetorical comments
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.
Thankfully it's no longer necessary to add useless comments due to the updated phpdoc coding style guide!
I'll remove the docblock.
|
||
$this->assertSame($testData, $pageCache->load($testKey)); | ||
} | ||
} |
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.
@larsroettig didn't get which line you talked about...
*/ | ||
$cacheInfo = $this->deploymentConfig->getConfigData(FrontendPool::KEY_CACHE); | ||
if (null !== $cacheInfo) { | ||
return array_merge($this->_frontendSettings, $cacheInfo[FrontendPool::KEY_FRONTEND_CACHE]); | ||
return array_replace_recursive($this->_frontendSettings, $cacheInfo[FrontendPool::KEY_FRONTEND_CACHE]); |
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.
Let's see if it won't break anything else.
Hi @orlangur, thank you for the review. |
✔️ QA passed |
@Vinai, could you please check the following failures in unit tests? |
cb5c342
to
78c825a
Compare
@nmalevanec Thank you for notifying me - I fixed and expanded the unit test cases. |
@Vinai, unfortunately we've encountered some problem after your fix. Could you please take a look at such scenario:
Expected resultActual result |
Good catch! My guess is the fix uncovered another bug that was masked by the regular cache and the page cache sharing the storage folder. I'll check what is causing the issue. |
Hi @sivaschenko, thank you for the review.
|
✔️ QA passed |
Hi @sidolov, |
Hi @ihor-sviziev , we faced the build failures with provided changes. I'll add more info about failures as soon as possible |
@ihor-sviziev @sidolov Thanks for the follow up! I'm quite curious hear what issues occurred during the build and am happy to help fixing them if I can. |
Hi @Vinai, thank you for your contribution! |
Description
In a native Magento 2 installation both the page_cache and the default cache is stored in the
var/cache
directory. Thevar/page_cache
directory is not used, even, though it is configured in di.xml.This makes it impossible to use
bin/magento cache:flush full_page
to only clear the FPC, as it will also flush the cache directory.The reason is any cache options configured in
di.xml
are lost if any configuration for a cache frontend is present inapp/etc/env.php
.During the Magento installation a cache id_prefix for both the default and the page_cache frontends are written to the
app/etc/env.php
.The bug was introduced by the PR: #18641
(note: the issue that was solved by that PR is also relevant for non-filesystem cache backends.)
In the method body of
\Magento\Framework\App\Cache\Frontend\Pool::_getCacheSettings
the original comment read:This reasoning of the original comment applies only if the backend type is changed, but not if an option is added to be used with the default.
Fixed Issues
This PR will merge the deployment configuration and the
di.xml
configuration usingarray_replace_recursive
instead ofarray_merge
, as cache settings that are not used by other cache backends don't do any harm, and still can be changed by overwriting them when needed.An alternative implementation of the solution checked if the
page_cache
backend was set to a different value of thedefault
cache frontend, but that added a lot of additional coupling and in favor of simplicity I believe the solution in this PR is better.The above fix revealed a bug that was masked before, namely that the when the built in page cache was is used, moving a category does not clean the appropriate cache records.
With varnish this issue does not occur because there the category top navigation is rendered as an ESI block, which is associated with all category ID cache tags (
cat_c_<ID>
).The page cache records however are only associated with the generic category cache tag (
cat_c
).Moving a category only cleans records that are associated with the category ID cache tag.
The solution is implemented as an event observer for the
category_move
event, which cleans the generic category cache tag if the built in page cache is used.Manual testing scenarios
var/page_cache
is empty andvar/cache
is not emptybin/magento cache:flush full_page
var/cache
is emptyAfter the patch is applied
var/page_cache
will no longer be empty after a page is accessed andbin/magento cache:flush full_page
will only flushvar/page_cache
Contribution checklist