8000 [Cache] fix warming up cache.system and apcu by nicolas-grekas · Pull Request #30331 · symfony/symfony · GitHub
[go: up one dir, main page]

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
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions src/Symfony/Component/Cache/Adapter/AbstractAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ function ($deferred, $namespace, &$expiredIds) use ($getId) {
}

/**
* Returns an ApcuAdapter if supported, a PhpFilesAdapter otherwise.
* Returns the best possible adapter that your runtime supports.
*
* Using ApcuAdapter makes system caches compatible with read-only filesystems.
*
Expand All @@ -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.

{
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.

if (null !== $logger) {
$opcache->setLogger($logger);
}

if (!self::$apcuSupported) {
$opcache = new PhpFilesAdapter($namespace, $defaultLifetime, $directory, true);
if (null !== $logger) {
$opcache->setLogger($logger);
}

if (!self::$apcuSupported = self::$apcuSupported ?? ApcuAdapter::isSupported()) {
return $opcache;
}

Expand All @@ -128,7 +124,7 @@ public static function createSystemCache($namespace, $defaultLifetime, $version,
$apcu->setLogger($logger);
}

return $apcu;
return new ChainAdapter([$apcu, $opcache]);
}

public static function createConnection($dsn, array $options = [])
Expand Down
0