Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Cache] fix warming up cache.system and apcu #30331

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

Merged
merged 1 commit into from
Feb 23, 2019

Conversation

nicolas-grekas
Copy link
Member

@nicolas-grekas nicolas-grekas commented Feb 21, 2019

Q A
Branch? 4.2
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #29601, #29877
License MIT
Doc PR -

@nicolas-grekas nicolas-grekas added this to the 4.2 milestone Feb 21, 2019
@nicolas-grekas nicolas-grekas changed the base branch from master to 4.2 February 21, 2019 13:36
@@ -108,16 +108,12 @@ function ($deferred, $namespace, &$expiredIds) use ($getId) {
*/
public static function createSystemCache($namespace, $defaultLifetime, $version, $directory, LoggerInterface $logger = null)
{
if (null === self::$apcuSupported) {
self::$apcuSupported = ApcuAdapter::isSupported();
$opcache = new PhpFilesAdapter($namespace, $defaultLifetime, $directory, true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no PhpFilesAdapter::isSupported(); falling back to FilesystemAdapter?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, unconditional is simpler and we don't care if you don't have opcache :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but, if the user does not have opcache or apcu, then you get no caching at all? possible hard to debug? up to the user to manually configure?

Copy link
Contributor

@bendavies bendavies Feb 21, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just looked at it does sort of fallback to filesystem in 4.1 FYI

public static function createSystemCache($namespace, $defaultLifetime, $version, $directory, LoggerInterface $logger = null)
{
if (null === self::$apcuSupported) {
self::$apcuSupported = ApcuAdapter::isSupported();
}
if (!self::$apcuSupported && null === self::$phpFilesSupported) {
self::$phpFilesSupported = PhpFilesAdapter::isSupported();
}
if (self::$phpFilesSupported) {
$opcache = new PhpFilesAdapter($namespace, $defaultLifetime, $directory);
if (null !== $logger) {
$opcache->setLogger($logger);
}
return $opcache;
}
$fs = new FilesystemAdapter($namespace, $defaultLifetime, $directory);
if (null !== $logger) {
$fs->setLogger($logger);
}
if (!self::$apcuSupported) {
return $fs;
}
$apcu = new ApcuAdapter($namespace, (int) $defaultLifetime / 5, $version);
if ('cli' === \PHP_SAPI && !filter_var(ini_get('apc.enable_cli'), FILTER_VALIDATE_BOOLEAN)) {
$apcu->setLogger(new NullLogger());
} elseif (null !== $logger) {
$apcu->setLogger($logger);
}
return new ChainAdapter([$apcu, $fs]);

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you don't have opcache, you don't care about that

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no opcache means you will still have the cache - but php will parse the files all the time

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah yes! gotcha.

@nicolas-grekas nicolas-grekas changed the title Cache system [Cache] fix warming up cache.system and apcu Feb 21, 2019
@dkarlovi
Copy link
Contributor

Maybe related? #29877

Copy link
Contributor

@dkarlovi dkarlovi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirming this fix brings back my test suite runtime from 4.2 amount (9:25) back to 4.1 amount (4:10).

Since it's a regression, a test is probably required to avoid having it reappear?

@nicolas-grekas
Copy link
Member Author

I don't think a test case would have prevented the change - I would have changed the tests at the time actually.

@@ -108,16 +108,12 @@ function ($deferred, $namespace, &$expiredIds) use ($getId) {
*/
public static function createSystemCache($namespace, $defaultLifetime, $version, $directory, LoggerInterface $logger = null)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Returns an ApcuAdapter if supported, a PhpFilesAdapter otherwise.

Does not seem to be precise anymore.

@dkarlovi
Copy link
Contributor

I meant adding a test would prevent a future regression.

Also, this doesn't seem to fix #29877 since that issue is due to incorrectly detecting APCu in CLI.

@nicolas-grekas nicolas-grekas merged commit b0a85ad into symfony:4.2 Feb 23, 2019
nicolas-grekas added a commit that referenced this pull request Feb 23, 2019
This PR was merged into the 4.2 branch.

Discussion
----------

[Cache] fix warming up cache.system and apcu

| Q             | A
| ------------- | ---
| Branch?       | 4.2
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #29601, #29877
| License       | MIT
| Doc PR        | -

Commits
-------

b0a85ad [Cache] fix warming up cache.system and apcu
@nicolas-grekas nicolas-grekas deleted the cache-system branch February 23, 2019 16:37
@fabpot fabpot mentioned this pull request Mar 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants