Skip to content
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 Pass PSR6 caches to ChainAdapter #10506

Merged
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
24 changes: 18 additions & 6 deletions src/Core/Cache/DefaultCacheFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,26 @@ public function create($service, array $args = [])
}

// Create filesystem cache
$fs = $this->createCache(FilesystemAdapter::class, [$namespace, $defaultLifetime, $directory], $useInjector);
if (!$apcuSupported) {
return $fs;
return $this->createCache(
FilesystemAdapter::class,
[$namespace, $defaultLifetime, $directory],
$useInjector
);
}

// Chain this cache with ApcuCache
// Create PSR6 filesystem + apcu cache's wrapped in a PSR6 chain adapter, then wrap in a PSR16 class
$fs = $this->instantiateCache(
FilesystemAdapter::class,
[$namespace, $defaultLifetime, $directory],
$useInjector
);

// Note that the cache lifetime will be shorter there by default, to ensure there's enough
// resources for "hot cache" items in APCu as a resource constrained in memory cache.
$apcuNamespace = $namespace . ($namespace ? '_' : '') . md5(BASE_PATH);
$lifetime = (int) $defaultLifetime / 5;
$apcu = $this->createCache(ApcuAdapter::class, [$apcuNamespace, $lifetime, $version], $useInjector);
$apcu = $this->instantiateCache(ApcuAdapter::class, [$apcuNamespace, $lifetime, $version], $useInjector);

return $this->createCache(ChainAdapter::class, [[$apcu, $fs]], $useInjector);
}
Expand Down Expand Up @@ -129,8 +138,11 @@ protected function isPHPFilesSupported()
* - https://symfony.com/doc/current/components/cache/psr6_psr16_adapters.html#using-a-psr-6-cache-object-as-a-psr-16-cache
* - https://github.com/php-fig/simple-cache
*/
protected function createCache(string $class, array $args, bool $useInjector = true): CacheInterface
{
protected function createCache(
string $class,
array $args,
bool $useInjector = true
): CacheInterface {
$loggerAdded = false;
$classIsPsr6 = is_a($class, CacheItemPoolInterface::class, true);
$classIsPsr16 = is_a($class, CacheInterface::class, true);
Expand Down