8000 [Cache] deprecate all PSR-16 adapters, provide Psr16Cache instead · symfony/symfony@3c06f7d · GitHub
[go: up one dir, main page]

Skip to content

Commit 3c06f7d

Browse files
[Cache] deprecate all PSR-16 adapters, provide Psr16Cache instead
1 parent 562448a commit 3c06f7d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+752
-351
lines changed

UPGRADE-4.3.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
UPGRADE FROM 4.2 to 4.3
22
=======================
33

4+
Cache
5+
-----
6+
7+
* The `psr/simple-cache` dependency has been removed - run `composer require psr/simple-cache` if you need it.
8+
* Deprecated all PSR-16 adapters, use `Psr16Cache` or `Symfony\Contracts\Cache\CacheInterface` implementations instead.
9+
* Deprecated `SimpleCacheAdapter`, use `Psr16Adapter instead.
10+
411
Config
512
------
613

UPGRADE-5.0.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ Cache
1010
-----
1111

1212
* Removed `CacheItem::getPreviousTags()`, use `CacheItem::getMetadata()` instead.
13+
* Removed all PSR-16 adapters, use `Psr16Cache` or `Symfony\Contracts\Cache\CacheInterface` implementations instead.
14+
* Removed `SimpleCacheAdapter`, use `Psr16Adapter instead.
1315

1416
Config
1517
------
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Cache\Adapter;
13+
14+
use Psr\SimpleCache\CacheInterface;
15+
use Symfony\Component\Cache\PruneableInterface;
16+
use Symfony\Component\Cache\ResettableInterface;
17+
use Symfony\Component\Cache\Traits\ProxyTrait;
18+
19+
/**
20+
* Turns a PSR-16 cache into a PSR-6 one.
21+
*
22+
* @author Nicolas Grekas <p@tchwork.com>
23+
*/
24+
class Psr16Adapter extends AbstractAdapter implements PruneableInterface, ResettableInterface
25+
{
26+
use ProxyTrait;
27+
28+
private $miss;
29+
30+
public function __construct(CacheInterface $pool, string $namespace = '', int $defaultLifetime = 0)
31+
{
32+
parent::__construct($namespace, $defaultLifetime);
33+
34+
$this->pool = $pool;
35+
$this->miss = new \stdClass();
36+
}
37+
38+
/**
39+
* {@inheritdoc}
40+
*/
41+
protected function doFetch(array $ids)
42+
{
43+
foreach ($this->pool->getMultiple($ids, $this->miss) as $key => $value) {
44+
if ($this->miss !== $value) {
45+
yield $key => $value;
46+
}
47+
}
48+
}
49+
50+
/**
51+
* {@inheritdoc}
52+
*/
53+
protected function doHave($id)
54+
{
55+
return $this->pool->has($id);
56+
}
57+
58+
/**
59+
* {@inheritdoc}
60+
*/
61+
protected function doClear($namespace)
62+
{
63+
return $this->pool->clear();
64+
}
65+
66+
/**
67+
* {@inheritdoc}
68+
*/
69+
protected function doDelete(array $ids)
70+
{
71+
return $this->pool->deleteMultiple($ids);
72+
}
73+
74+
/**
75+
* {@inheritdoc}
76+
*/
77+
protected function doSave(array $values, $lifetime)
78+
{
79+
return $this->pool->setMultiple($values, 0 === $lifetime ? null : $lifetime);
80+
}
81+
}

src/Symfony/Component/Cache/Adapter/SimpleCacheAdapter.php

Lines changed: 3 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -11,69 +11,11 @@
1111

1212
namespace Symfony\Component\Cache\Adapter;
1313

14-
use Psr\SimpleCache\CacheInterface;
15-
use Symfony\Component\Cache\PruneableInterface;
16-
use Symfony\Component\Cache\ResettableInterface;
17-
use Symfony\Component\Cache\Traits\ProxyTrait;
14+
@trigger_error(sprintf('The "%s" class is @deprecated since Symfony 4.3, use "Psr16Adapter" instead.', SimpleCacheAdapter::class), E_USER_DEPRECATED);
1815

1916
/**
20-
* @author Nicolas Grekas <p@tchwork.com>
17+
* @deprecated since Symfony 4.3, use Psr16Adapter instead.
2118
*/
22-
class SimpleCacheAdapter extends AbstractAdapter implements PruneableInterface, ResettableInterface
19+
class SimpleCacheAdapter extends Psr16Adapter
2320
{
24-
use ProxyTrait;
25-
26-
private $miss;
27-
28-
public function __construct(CacheInterface $pool, string $namespace = '', int $defaultLifetime = 0)
29-
{
30-
parent::__construct($namespace, $defaultLifetime);
31-
32-
$this->pool = $pool;
33-
$this->miss = new \stdClass();
34-
}
35-
36-
/**
37-
* {@inheritdoc}
38-
*/
39-
protected function doFetch(array $ids)
40-
{
41-
foreach ($this->pool->getMultiple($ids, $this->miss) as $key => $value) {
42-
if ($this->miss !== $value) {
43-
yield $key => $value;
44-
}
45-
}
46-
}
47-
48-
/**
49-
* {@inheritdoc}
50-
*/
51-
protected function doHave($id)
52-
{
53-
return $this->pool->has($id);
54-
}
55-
56-
/**
57-
* {@inheritdoc}
58-
*/
59-
protected function doClear($namespace)
60-
{
61-
return $this->pool->clear();
62-
}
63-
64-
/**
65-
* {@inheritdoc}
66-
*/
67-
protected function doDelete(array $ids)
68-
{
69-
return $this->pool->deleteMultiple($ids);
70-
}
71-
72-
/**
73-
* {@inheritdoc}
74-
*/
75-
protected function doSave(array $values, $lifetime)
76-
{
77-
return $this->pool->setMultiple($values, 0 === $lifetime ? null : $lifetime);
78-
}
7921
}

src/Symfony/Component/Cache/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
CHANGELOG
22
=========
33

4+
4.3.0
5+
-----
6+
7+
* removed `psr/simple-cache` dependency, run `composer require psr/simple-cache` if you need it
8+
* deprecated all PSR-16 adapters, use `Psr16Cache` or `Symfony\Contracts\Cache\CacheInterface` implementations instead
9+
* deprecated `SimpleCacheAdapter`, use `Psr16Adapter instead
10+
411
4.2.0
512
-----
613

src/Symfony/Component/Cache/LockRegistry.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class LockRegistry
4545
__DIR__.\DIRECTORY_SEPARATOR.'Adapter'.\DIRECTORY_SEPARATOR.'PhpArrayAdapter.php',
4646
__DIR__.\DIRECTORY_SEPARATOR.'Adapter'.\DIRECTORY_SEPARATOR.'PhpFilesAdapter.php',
4747
__DIR__.\DIRECTORY_SEPARATOR.'Adapter'.\DIRECTORY_SEPARATOR.'ProxyAdapter.php',
48+
__DIR__.\DIRECTORY_SEPARATOR.'Adapter'.\DIRECTORY_SEPARATOR.'Psr16Adapter.php',
4849
__DIR__.\DIRECTORY_SEPARATOR.'Adapter'.\DIRECTORY_SEPARATOR.'RedisAdapter.php',
4950
__DIR__.\DIRECTORY_SEPARATOR.'Adapter'.\DIRECTORY_SEPARATOR.'SimpleCacheAdapter.php',
5051
__DIR__.\DIRECTORY_SEPARATOR.'Adapter'.\DIRECTORY_SEPARATOR.'TagAwareAdapter.php',

0 commit comments

Comments
 (0)
0