Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature #29236 [Cache] deprecate all PSR-16 adapters, provide Psr16Ca…
…che instead (nicolas-grekas) This PR was merged into the 4.3-dev branch. Discussion ---------- [Cache] deprecate all PSR-16 adapters, provide Psr16Cache instead | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | yes | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - As discussed in #28918, PSR-16 implementations are now mostly useless: either PSR-6 or contracts' CacheInterface is always a better fit. Let's deprecate them all but keep only a `Psr16Cache` to turn any PSR-6 implementation to a PSR-16 one. From the changelog: * removed `psr/simple-cache` dependency, run `composer require psr/simple-cache` if you need it * deprecated all PSR-16 adapters, use `Psr16Cache` or `Symfony\Contracts\Cache\CacheInterface` implementations instead * deprecated `SimpleCacheAdapter`, use `Psr16Adapter` instead * deprecated the "Psr\SimpleCache\CacheInterface" / "cache.app.simple" service, use "Symfony\Contracts\Cache\CacheInterface" / "cache.app" instead Commits ------- 5006be6 [Cache] deprecate all PSR-16 adapters, provide Psr16Cache instead
- Loading branch information
Showing
53 changed files
with
788 additions
and
385 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Cache\Adapter; | ||
|
||
use Psr\SimpleCache\CacheInterface; | ||
use Symfony\Component\Cache\PruneableInterface; | ||
use Symfony\Component\Cache\ResettableInterface; | ||
use Symfony\Component\Cache\Traits\ProxyTrait; | ||
|
||
/** | ||
* Turns a PSR-16 cache into a PSR-6 one. | ||
* | ||
* @author Nicolas Grekas <p@tchwork.com> | ||
*/ | ||
class Psr16Adapter extends AbstractAdapter implements PruneableInterface, ResettableInterface | ||
{ | ||
use ProxyTrait; | ||
|
||
private $miss; | ||
|
||
public function __construct(CacheInterface $pool, string $namespace = '', int $defaultLifetime = 0) | ||
{ | ||
parent::__construct($namespace, $defaultLifetime); | ||
|
||
$this->pool = $pool; | ||
$this->miss = new \stdClass(); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function doFetch(array $ids) | ||
{ | ||
foreach ($this->pool->getMultiple($ids, $this->miss) as $key => $value) { | ||
if ($this->miss !== $value) { | ||
yield $key => $value; | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function doHave($id) | ||
{ | ||
return $this->pool->has($id); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function doClear($namespace) | ||
{ | ||
return $this->pool->clear(); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function doDelete(array $ids) | ||
{ | ||
return $this->pool->deleteMultiple($ids); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function doSave(array $values, $lifetime) | ||
{ | ||
return $this->pool->setMultiple($values, 0 === $lifetime ? null : $lifetime); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.