8000 [Cache] leverage Contracts\Cache · symfony/symfony@8dbcf87 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8dbcf87

Browse files
[Cache] leverage Contracts\Cache
1 parent 0868ff4 commit 8dbcf87

13 files changed

+40
-93
lines changed

src/Symfony/Bundle/FrameworkBundle/Resources/config/cache.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,9 @@
149149
<service id="Psr\Cache\CacheItemPoolInterface" alias="cache.app" />
150150
<service id="Psr\SimpleCache\CacheInterface" alias="cache.app.simple" />
151151
<service id="Symfony\Component\Cache\Adapter\AdapterInterface" alias="cache.app" />
152-
<service id="Symfony\Component\Cache\CacheInterface" alias="cache.app.taggable" />
152+
<service id="Symfony\Contracts\Cache\CacheInterface" alias="cache.app" />
153+
<service id="Symfony\Contracts\Cache\ExtendedCacheInterface" alias="cache.app" />
154+
<service id="Symfony\Contracts\Cache\TagAwareCacheInterface" alias="cache.app.taggable" />
155+
<service id="Symfony\Contracts\Cache\ExtendedTagAwareCacheInterface" alias="cache.app.taggable" />
153156
</services>
154157
</container>

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,17 @@
1515
use Psr\Log\LoggerAwareInterface;
1616
use Psr\Log\LoggerInterface;
1717
use Psr\Log\NullLogger;
18-
use Symfony\Component\Cache\CacheInterface;
1918
use Symfony\Component\Cache\CacheItem;
2019
use Symfony\Component\Cache\Exception\InvalidArgumentException;
2120
use Symfony\Component\Cache\ResettableInterface;
2221
use Symfony\Component\Cache\Traits\AbstractTrait;
2322
use Symfony\Component\Cache\Traits\GetTrait;
23+
use Symfony\Contracts\Cache\ExtendedCacheInterface;
2424

2525
/**
2626
* @author Nicolas Grekas <p@tchwork.com>
2727
*/
28-
abstract class AbstractAdapter implements AdapterInterface, CacheInterface, LoggerAwareInterface, ResettableInterface
28+
abstract class AbstractAdapter implements AdapterInterface, ExtendedCacheInterface, LoggerAwareInterface, ResettableInterface
2929
{
3030
use AbstractTrait;
3131
use GetTrait;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@
1313

1414
use Psr\Cache\CacheItemInterface;
1515
use Psr\Log\LoggerAwareInterface;
16-
use Symfony\Component\Cache\CacheInterface;
1716
use Symfony\Component\Cache\CacheItem;
1817
use Symfony\Component\Cache\ResettableInterface;
1918
use Symfony\Component\Cache\Traits\ArrayTrait;
19+
use Symfony\Contracts\Cache\ExtendedCacheInterface;
2020

2121
/**
2222
* @author Nicolas Grekas <p@tchwork.com>
2323
*/
24-
class ArrayAdapter implements AdapterInterface, CacheInterface, LoggerAwareInterface, ResettableInterface
24+
class ArrayAdapter implements AdapterInterface, ExtendedCacheInterface, LoggerAwareInterface, ResettableInterface
2525
{
2626
use ArrayTrait;
2727

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@
1313

1414
use Psr\Cache\CacheItemInterface;
1515
use Psr\Cache\CacheItemPoolInterface;
16-
use Symfony\Component\Cache\CacheInterface;
1716
use Symfony\Component\Cache\CacheItem;
1817
use Symfony\Component\Cache\Exception\InvalidArgumentException;
1918
use Symfony\Component\Cache\PruneableInterface;
2019
use Symfony\Component\Cache\ResettableInterface;
2120
use Symfony\Component\Cache\Traits\GetTrait;
21+
use Symfony\Contracts\Cache\CacheInterface;
22+
use Symfony\Contracts\Cache\ExtendedCacheInterface;
2223
use Symfony\Contracts\Service\ResetInterface;
2324

2425
/**
@@ -29,7 +30,7 @@
2930
*
3031
* @author Kévin Dunglas <dunglas@gmail.com>
3132
*/
32-
class ChainAdapter implements AdapterInterface, CacheInterface, PruneableInterface, ResettableInterface
33+
class ChainAdapter implements AdapterInterface, ExtendedCacheInterface, PruneableInterface, ResettableInterface
3334
{
3435
use GetTrait;
3536

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212
namespace Symfony\Component\Cache\Adapter;
1313

1414
use Psr\Cache\CacheItemInterface;
15-
use Symfony\Component\Cache\CacheInterface;
1615
use Symfony\Component\Cache\CacheItem;
16+
use Symfony\Contracts\Cache\ExtendedCacheInterface;
1717

1818
/**
1919
* @author Titouan Galopin <galopintitouan@gmail.com>
2020
*/
21-
class NullAdapter implements AdapterInterface, CacheInterface
21+
class NullAdapter implements AdapterInterface, ExtendedCacheInterface
2222
{
2323
private $createCacheItem;
2424

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@
1313

1414
use Psr\Cache\CacheItemInterface;
1515
use Psr\Cache\CacheItemPoolInterface;
16-
use Symfony\Component\Cache\CacheInterface;
1716
use Symfony\Component\Cache\CacheItem;
1817
use Symfony\Component\Cache\Exception\InvalidArgumentException;
1918
use Symfony\Component\Cache\Marshaller\DefaultMarshaller;
2019
use Symfony\Component\Cache\PruneableInterface;
2120
use Symfony\Component\Cache\ResettableInterface;
2221
use Symfony\Component\Cache\Traits\GetTrait;
2322
use Symfony\Component\Cache\Traits\PhpArrayTrait;
23+
use Symfony\Contracts\Cache\CacheInterface;
24+
use Symfony\Contracts\Cache\ExtendedCacheInterface;
2425

2526
/**
2627
* Caches items at warm up time using a PHP array that is stored in shared memory by OPCache since PHP 7.0.
@@ -29,7 +30,7 @@
2930
* @author Titouan Galopin <galopintitouan@gmail.com>
3031
* @author Nicolas Grekas <p@tchwork.com>
3132
*/
32-
class PhpArrayAdapter implements AdapterInterface, CacheInterface, PruneableInterface, ResettableInterface
33+
class PhpArrayAdapter implements AdapterInterface, ExtendedCacheInterface, PruneableInterface, ResettableInterface
3334
{
3435
use PhpArrayTrait;
3536
use GetTrait;

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,18 @@
1313

1414
use Psr\Cache\CacheItemInterface;
1515
use Psr\Cache\CacheItemPoolInterface;
16-
use Symfony\Component\Cache\CacheInterface;
1716
use Symfony\Component\Cache\CacheItem;
1817
use Symfony\Component\Cache\PruneableInterface;
1918
use Symfony\Component\Cache\ResettableInterface;
2019
use Symfony\Component\Cache\Traits\GetTrait;
2120
use Symfony\Component\Cache\Traits\ProxyTrait;
21+
use Symfony\Contracts\Cache\CacheInterface;
22+
use Symfony\Contracts\Cache\ExtendedCacheInterface;
2223

2324
/**
2425
* @author Nicolas Grekas <p@tchwork.com>
2526
*/
26-
class ProxyAdapter implements AdapterInterface, CacheInterface, PruneableInterface, ResettableInterface
27+
class ProxyAdapter implements AdapterInterface, ExtendedCacheInterface, PruneableInterface, ResettableInterface
2728
{
2829
use ProxyTrait;
2930
use GetTrait;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,17 @@
1313

1414
use Psr\Cache\CacheItemInterface;
1515
use Psr\Cache\InvalidArgumentException;
16-
use Symfony\Component\Cache\CacheInterface;
1716
use Symfony\Component\Cache\CacheItem;
1817
use Symfony\Component\Cache\PruneableInterface;
1918
use Symfony\Component\Cache\ResettableInterface;
2019
use Symfony\Component\Cache\Traits\GetTrait;
2120
use Symfony\Component\Cache\Traits\ProxyTrait;
21+
use Symfony\Contracts\Cache\ExtendedTagAwareCacheInterface;
2222

2323
/**
2424
* @author Nicolas Grekas <p@tchwork.com>
2525
*/
26-
class TagAwareAdapter implements CacheInterface, TagAwareAdapterInterface, PruneableInterface, ResettableInterface
26+
class TagAwareAdapter implements TagAwareAdapterInterface, ExtendedTagAwareCacheInterface, PruneableInterface, ResettableInterface
2727
{
2828
const TAGS_PREFIX = "\0tags\0";
2929

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@
1212
namespace Symfony\Component\Cache\Adapter;
1313

1414
use Psr\Cache\CacheItemInterface;
15-
use Symfony\Component\Cache\CacheInterface;
1615
use Symfony\Component\Cache\CacheItem;
1716
use Symfony\Component\Cache\PruneableInterface;
1817
use Symfony\Component\Cache\ResettableInterface;
18+
use Symfony\Contracts\Cache\CacheInterface;
19+
use Symfony\Contracts\Cache\ExtendedCacheInterface;
1920
use Symfony\Contracts\Service\ResetInterface;
2021

2122
/**
@@ -25,7 +26,7 @@
2526
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
2627
* @author Nicolas Grekas <p@tchwork.com>
2728
*/
28-
class TraceableAdapter implements AdapterInterface, CacheInterface, PruneableInterface, ResettableInterface
29+
class TraceableAdapter implements AdapterInterface, ExtendedCacheInterface, PruneableInterface, ResettableInterface
2930
{
3031
protected $pool;
3132
private $calls = array();

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111

1212
namespace Symfony\Component\Cache\Adapter;
1313

14-
use Symfony\Component\Cache\CacheInterface;
14+
use Symfony\Contracts\Cache\ExtendedTagAwareCacheInterface;
1515

1616
/**
1717
* @author Robin Chalas <robin.chalas@gmail.com>
1818
*/
19-
class TraceableTagAwareAdapter extends TraceableAdapter implements CacheInterface, TagAwareAdapterInterface
19+
class TraceableTagAwareAdapter extends TraceableAdapter implements TagAwareAdapterInterface, ExtendedTagAwareCacheInterface
2020
{
2121
public function __construct(TagAwareAdapterInterface $pool)
2222
{

src/Symfony/Component/Cache/CacheInterface.php

Lines changed: 0 additions & 37 deletions
This file was deleted.

src/Symfony/Component/Cache/CacheItem.php

Lines changed: 12 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -11,31 +11,16 @@
1111

1212
namespace Symfony\Component\Cache;
1313

14-
use Psr\Cache\CacheItemInterface;
1514
use Psr\Log\LoggerInterface;
1615
use Symfony\Component\Cache\Exception\InvalidArgumentException;
1716
use Symfony\Component\Cache\Exception\LogicException;
17+
use Symfony\Contracts\Cache\ItemInterface;
1818

1919
/**
2020
* @author Nicolas Grekas <p@tchwork.com>
2121
*/
22-
final class CacheItem implements CacheItemInterface
22+
final class CacheItem implements ItemInterface
2323
{
24-
/**
25-
* References the Unix timestamp stating when the item will expire.
26-
*/
27-
const METADATA_EXPIRY = 'expiry';
28-
29-
/**
30-
* References the time the item took to be created, in milliseconds.
31-
*/
32-
const METADATA_CTIME = 'ctime';
33-
34-
/**
35-
* References the list of tags that were assigned to the item, as string[].
36-
*/
37-
const METADATA_TAGS = 'tags';
38-
3924
private const METADATA_EXPIRY_OFFSET = 1527506807;
4025

4126
protected $key;
@@ -118,15 +103,9 @@ public function expiresAfter($time)
118103
}
119104

120105
/**
121-
* Adds a tag to a cache item.
122-
*
123-
* @param string|string[] $tags A tag or array of tags
124-
*
125-
* @return static
126-
*
127-
* @throws InvalidArgumentException When $tag is not valid
106+
* {@inheritdoc}
128107
*/
129-
public function tag($tags)
108+
public function tag($tags): ItemInterface
130109
{
131110
if (!$this->isTaggable) {
132111
throw new LogicException(sprintf('Cache item "%s" comes from a non tag-aware pool: you cannot tag it.', $this->key));
@@ -153,6 +132,14 @@ public function tag($tags)
153132
return $this;
154133
}
155134

135+
/**
136+
* {@inheritdoc}
137+
*/
138+
public function getMetadata(): array
139+
{
140+
return $this->metadata;
141+
}
142+
156143
/**
157144
* Returns the list of tags bound to the value coming from the pool storage if any.
158145
*
@@ -167,16 +154,6 @@ public function getPreviousTags()
167154
return $this->metadata[self::METADATA_TAGS] ?? array();
168155
}
169156

170-
/**
171-
* Returns a list of metadata info that were saved alongside with the cached value.
172-
*
173-
* See public CacheItem::METADATA_* consts for keys potentially found in the returned array.
174-
*/
175-
public function getMetadata(): array
176-
{
177-
return $this->metadata;
178-
}
179-
180157
/**
181158
* Validates a cache key according to PSR-6.
182159
*

src/Symfony/Component/Cache/Exception/LogicException.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111

1212
namespace Symfony\Component\Cache\Exception;
1313

14-
use Psr\Cache\InvalidArgumentException as Psr6CacheInterface;
15-
use Psr\SimpleCache\InvalidArgumentException as SimpleCacheInterface;
14+
use Psr\Cache\CacheException as Psr6CacheInterface;
15+
use Psr\SimpleCache\CacheException as SimpleCacheInterface;
1616

1717
class LogicException extends \LogicException implements Psr6CacheInterface, SimpleCacheInterface
1818
{

0 commit comments

Comments
 (0)
0